
今天即兴的学了一会JavaScript的先关东西setinterval(定时器的使用)经常会用到图片的无缝滚动。。。
下面是一个时间的设置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
<html> <head> <title></title> <meta charset="utf-8"> </head> <script> function toDou(n) { if(n<10) { return '0'+n; } else { return ''+n; } } window.onload=(){ var aImg=document.getElementsByTagName('img'); function tick(){ var oDate=new Date(); var str=toDou(oDate.getHours())+toDou(oDate.getMinutes())+toDou(oDate.getSeconds()); for (var i=0;i<aImg.length;i++) { aImg[i].src='img/'+str[i]+'.png'; } }; setInterval(tick,1000); tick(); }; </script> <body style="background:black;color:white;font-size:50px;"> <img src="img/0.png"/> <img src="img/0.png"/> : <img src="img/0.png"/> <img src="img/0.png"/> : <img src="img/0.png"/> <img src="img/0.png"/> </body> </html>
|
近期评论