描述:当用户打开页面之后,显示对联广告,广告在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 9, 2018
If you think my article is useful to you, please feel free to appreciate