您的位置:首页 > Web前端 > JavaScript

JavaScript 定时器制作一个弹窗小广告

2016-05-03 17:19 441 查看
<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>


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息