定时器 — 弹窗广告

xiaoxiao2021-02-28  12

页面打开之后2秒钟开始弹出广告,广告弹出3秒钟之后自动关闭广告(只执行一次);

例如:看视频时,刚打开视频5秒钟后,右下角弹出一个广告,过5秒自动关闭广告;

html:

<img src="img/ad.png" alt="广告" id="ad">

css:

body {background:url(img/bg.png) no-repeat center 0; text-align: center;} img {display: none;}

js:

var ad = document.getElementById('ad'); var timer = null; timer = setTimeout(function(){ ad.style.display = 'inline-block'; // 广告出现三秒钟之后自动关闭也是需要定时器,如下: setTimeout(function(){ ad.style.display = 'none'; },3000);//3秒钟之后自动关闭定时器 },2000);//2秒之后执行该定时器
转载请注明原文地址: https://www.6miu.com/read-750271.html

最新回复(0)