首页 > 代码库 > 设计图片反复闪,点击后停止(设计定时器)
设计图片反复闪,点击后停止(设计定时器)
<!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="http://www.mamicode.com/按钮" 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>
设计图片反复闪,点击后停止(设计定时器)