<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
div{
width: 100px;
height: 100px;
background-color: red;
position: fixed;
bottom: 0;
right: 0;
display: none;
}
#close{
position: absolute;
left: -20px;
}
</style>
</head>
<body>
<div id="dis">
<span id="close" onclick="btn();">X</span>
过<span id="second">5</span>秒后关闭
</div>
</body>
<script>
var s = document.getElementById("dis")
var second = document.getElementById("second");
var timer = null;
var timeOut = setTimeout(function(){
s.style.display = "block";
timer = setInterval(function(){
second.innerText--;
if(second.innerText == 0){
clearInterval(timer)
s.style.display = "none";
}
},1000)
},1000)
function btn(){
s.style.display = "none";
clearInterval(timer);
}
</script>
JavaScript 定时器制作一个弹窗小广告
最新推荐文章于 2023-03-01 15:19:56 发布