设计图片反复闪,点击后停止(设计定时器)

Posted on 2017-01-03 23:22  isayhappy  阅读(253)  评论(0编辑  收藏  举报

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<style>
div{
width: 200px;
height: 200px;
background-color: blue;
position: absolute;
left: 60px;
visibility: visible;
}
</style>
<body>
<input type="button" value="按钮" id="btn"/>
<div id="demo"></div>
</body>
<script>

//定时器函数show

function show(){
var demo=document.getElementById('demo');
if(demo.style.visibility == "visible"){
demo.style.visibility ="hidden";
}else{
demo.style.visibility='visible';
}
var timer=setTimeout('show()',300);
var btn=document.getElementById('btn');
btn.onclick=function(){//点击取消定时器
clearInterval(timer);
}
}
show();//调用定时器
</script>
</html>

Copyright © 2024 isayhappy
Powered by .NET 8.0 on Kubernetes