js实现广告弹窗

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .adver{
        width: 300px;
        height: 200px;
        border: 1px solid #ccc;
        background-color: pink;
        position: absolute;
        top: 100px;
        right: 0;
    }
    span{
        width: 40px;
        height: 25px;
        position: absolute;
        top: 0;
        right: 0;
        background-color: #ccc;
        color: #fff;
        text-align: center;
    }
</style>
<body>
    <div class="adver">
        <span>关闭</span>
    </div>
</body>
<script>
// 获取操作对象
var adver = document.querySelector('.adver');
//延迟消失
// setTimeout(function(){
//     // 让div消失
//     //display:none  opacity:0  right:-300px
//     adver.style.display = 'none'
// },3000)

var span = document.querySelector('span');
// 给操作对象添加事件
span.onclick = function(){
    // 当点击关闭按钮让整个盒子隐藏
    adver.style.display = 'none'
    // 设置延时定时器 
    setTimeout(function(){
        adver.style.display = 'block'
    },3000)
}
</script>
</html>
复制代码

效果图:点击关闭即可隐藏 - 3秒过后既又重新出现

 

posted @   包歌  阅读(751)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示