Loki3626 2022-05-24 22:05 采纳率: 0%
浏览 19

点击隐藏盒子并设置倒计时显示,倒计时不规范

问题遇到的现象和发生背景

做一个类似流氓广告的效果,就是点击关闭之后只是在界面上隐藏,实际上有个倒计时,倒计时结束之后广告又重新显示在原来的位置

问题相关代码,请勿粘贴截图
 <style>
        .father{
            position: fixed;
            right: 0;
            bottom: 0;
            width: 200px;
            height: 300px;
            background-color: orange;
        }
        .son{
            position: fixed;
            bottom: 280px;
            right: 0;
            line-height: 20px;
            text-align: center;
            width: 20px;
            height: 20px;
            background-color: #ccc;
        }
    </style>
<body>
    <div class="father">
        <div class="son">x</div>
    </div>
    <script>
        var son = document.querySelector('.son')
        var father = document.querySelector('.father')
        son.onclick = function(){
            father.style.display = 'none';
        }
        var time = setInterval(function(){
                father.style.display = 'block'
            },5000)  
    </script>
</body>
运行结果及报错内容

运行之后感觉每一次倒计时都不一样

我想要达到的结果

让广告在每次点击关闭之后都是5秒之后重新显示

  • 写回答

1条回答 默认 最新

  • Heerey525 前端领域新星创作者 2022-05-24 22:51
    关注
    var son = document.querySelector(".son");
    var father = document.querySelector(".father");
    son.onclick = function () {
      father.style.display = "none";
      setTimeout(function () {
        father.style.display = "block";
      }, 5000);
    };
    
    评论

报告相同问题?

问题事件

  • 创建了问题 5月24日

悬赏问题

  • ¥15 android 集成sentry上报时报错。
  • ¥50 win10链接MySQL
  • ¥35 跳过我的世界插件ip验证
  • ¥15 抖音看过的视频,缓存在哪个文件
  • ¥15 自定义损失函数报输入参数的数目不足
  • ¥15 如果我想学习C大家有是的的资料吗
  • ¥15 根据文件名称对文件进行排序
  • ¥15 deploylinux的ubuntu系统无法成功安装使用MySQL❓
  • ¥15 有人会用py或者r画这种图吗
  • ¥15 MOD04_3K图像预处理