制作一个定时器来弹出和隐藏广告
主要运用的函数:
setInterval(“show1()”,2000); //设置2000ms后运行函数show1()
clearInterval(time); //清除定时器
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="JQ/jquery-1.8.3.js"> </script>
<script type="text/javascript">
$(function(){
//显示图片的定时操作
time=setInterval("show1()",2000);
})
function show1(){
//获取图片
$("#img1").show(1000);
//清除图片定时操作
clearInterval(time);
//
time=setInterval("hide1()",3000);
}
function hide1(){
$("#img1").hide();
clearInterval(time);
}
</script>
<style>
img{
width: 400px;
height: 400px;
align-self: center;
}
</style>
</head>
<body>
<img id="img1" src="img/IMG_20190518_081432.jpg" style="display: none;"/>
</body>
</html>