定时器
2018-07-14 本文已影响0人
司马皮砸瓜
<div id="dv">
<img src="images/heihei.jpg" alt="">
<img src="images/lyml.jpg" alt="">
</div>
var btn1=document.getElementById('btn1');
var btn2=document.getElementById('btn2');
var fn4='';
btn1.onclick=function () {
fn4=setInterval(function () {
var x=parseInt(Math.random()*100+1);
var y=parseInt(Math.random()*100+1);
dv.style.left=x+'px';
dv.style.top=y+'px';
},10);
};
btn2.onclick=function () {
clearInterval(fn4);
var im=document.getElementById('im');
function fn1() {
var td=new Date();
var hour=td.getHours();
var second=td.getSeconds();
hour=hour<10?'0'+hour:hour;
second=second<10?'0'+second:second;
im.src="meimei/"+hour+'_'+second+".jpg";
}
fn1();
setInterval(fn1,1000);