孙肖宁

定时关闭广告
描述:当用户打开页面之后,显示对联广告,广告在5秒之后关闭。实现代码:<!DOCTYPE html> ...
扫描右侧二维码阅读全文
09
2018/04

定时关闭广告

描述:当用户打开页面之后,显示对联广告,广告在5秒之后关闭。
实现代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定时关闭广告</title>
    <style>
        *{
            margin: 0;
            border: 0;
        }
        .content{
            width: 1200px;
            height: 1200px;
            //background: coral;
            margin: 0 auto;
        }
        img{
            position: fixed;
            top: 50%;
            margin-top: -220px;
        }
        .img1{
            left: 10px;
        }
        .img2{
            right: 10px;
        }
    </style>
</head>
<body>
<div class="content"></div>
<img class="img1" src="./images/1.gif" alt="">
<img class="img2" src="./images/2.gif" alt="">
</body>
</html>
<script>
    window.onload = function () {
        var imgArr = document.getElementsByTagName("img");
        setTimeout(fn,5000);
        function fn() {
            imgArr[0].style.display = "none";
            imgArr[1].style.display = "none";
        }
    }
</script>
Last modification:April 9th, 2018 at 10:14 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment