使用计算机时钟每分钟更改一次图像来计时更改
我想每分钟改变一个图像。当计算机时钟从 8:50 移动到 8:51,然后从 8:52 一直回到 8:49 时,我希望我的图片从 0001.jpg 变为 0002.jpg,再到 0003.jpg,一直到 1440。 .jpg。
由于我将使用计算机时钟,因此我对使用 JavaScript 很感兴趣。我也刚刚开始,所以完整的代码(这太棒了!)可能不是我需要的。相反,我正在寻找一个起点,也许还有一个前进的方向。您知道的任何在线资源也会有帮助
I want to change an image every minute. When the computer's clock moves from 8:50 to 8:51 then to 8:52 all the way back to 8:49 I want my picture to change from 0001.jpg to 0002.jpg to 0003.jpg all the way to 1440.jpg.
Since I am going to be using the computer's clock, I am interested in using JavaScript. I am also just starting out, so full code (which would be awesome!) is probably not what I need. Instead, I am looking for a place to start and maybe a direction to go. Any resources online that you know of would also be helpful
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
计算距离下一分钟开始还有多少秒,然后使用 setTimeout 开始旋转图片。使用
setInterval
每 60000 毫秒执行一次。您可以在此处了解有关这两个函数的更多信息
compute how many seconds until the next minute starts, then using
setTimeout
begin rotating the pictures. UsesetInterval
to do so every 60000 milliseconds.You can read more about both functions here
您需要研究
setInterval()
。代码看起来像这样:
Mozilla 开发人员中心网站有很多很棒的 JavaScript 和 DOM 引用。我还建议学习使用 JSLint,它将有助于避免导致头痛的愚蠢语法错误。我建议阅读 Douglas Crockford 的书 JavaSript: The Good Parts 和 Stoyan Stefanov 的面向对象的 JavaScript,它们都是学习 JavaScript 的优秀书籍。
You'll want to study up on
setInterval()
.The code would look something like this:
The Mozilla Developer Center site has lots of great JavaScript and DOM references. I would also suggest learning to use JSLint, it will help a lot in avoiding stupid syntax errors that will cause headaches. I would suggest reading Douglas Crockford's book JavaSript: The Good Parts and Stoyan Stefanov's Object-Oriented JavaScript they are both excellent books to learn JavaScript from.
将下面的代码放在页面的主体中:
如果您从 Javascript 开始,一个很好的参考是 MDC
Place the code below in the BODY of a page:
If you start with Javascript a good reference is MDC
如果你想做到这一点与计算机时钟绑定。使用延迟小于一秒 (<1000) 的
setInterval
并使用Date()
检查实际时间。这样您就可以根据时钟进行更改。If you want to do this tied to the computer clock. Use the
setInterval
with a delay less than a second (<1000) and check the actual time withDate()
. This way you can make your changes according to the clock.