0

我需要每个 IP 每天显示一次“div 覆盖”...覆盖 div 显示 5 秒然后关闭。我只需要显示一次,然后就不需要了。这是代码...

<script type="text/javascript">
   function toggleOverlay(){
var overlay = document.getElementById('overlay');
var specialBox = document.getElementById('specialBox');
overlay.style.opacity = .8;
if(overlay.style.display == "block"){
    overlay.style.display = "none";
    specialBox.style.display = "none";
} else {
    overlay.style.display = "block";
    specialBox.style.display = "block";
}
    }
</script>

<script>
  function timerdiv()
   {
   setTimeout(function(){return toggleOverlay()},5000);
   }
</script>


<body Onload="toggleOverlay();timerdiv();">

<!-- Start Overlay -->
<div id="overlay"></div>
<!-- End Overlay -->
<!-- Start Special Centered Box -->
<div id="specialBox">

 TEST Overlay BOX

</div>

 <!-- Start Special Centered Box -->
 <!-- Start Normal Page Content -->

<div id="wrapper">        

  Hello World!

</div>

 </body>

我有这个代码..我已经更改但我无法正常运行..每次访问时都显示覆盖 div

<script type="text/javascript"        src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery.cookie.js"></script>
    <script type="text/javascript">                                         
    $(document).ready(function() {
        if( $.cookie('showOnlyOne') ){
            //it is still within the day
            //hide the div
            $('#overlay').hide();

        } else {
            //either cookie already expired, or user never visit the site
            //create the cookie
            $.cookie('showOnlyOne', 'showOnlyOne', { expires: 1 });

            //and display the div
            $('#overlay').show();

        }
    });
    </script>

编辑:

好的......在与代码斗争了几个小时之后。我找到了解决方案,在这里分享,以防将来有人服务。

<head>

<style type="text/css">
div#overlay {
display: none;
z-index: 2;
background: #000;
position: fixed;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
text-align: center;
opacity: 0.8;
}
div#specialBox {
display: none;
position: relative;
z-index: 3;
margin: 150px auto 0px auto;
width: 500px; 
height: 300px;
background: #FFF;
color: #000;
 }
div#wrapper {
position:absolute;
top: 0px;
left: 20%;
padding-left:24px;
  }
     </style>


  <script type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery.cookie.js"></script>
    <script type="text/javascript">                                         
    $(document).ready(function() {
        if( $.cookie('showOnlyOne') ){
            //it is still within the day
            //hide the div
           $('#overlay').hide();
          $('#specialBox').hide();
        } else {
            //either cookie already expired, or user never visit the site
            //create the cookie
            $.cookie('showOnlyOne', 'showOnlyOne', { expires: 1 });

            //and display the div
          $('#overlay').show();
          $('#specialBox').show();
          $('#specialBox').delay(3200).fadeOut(300);
          $('#overlay').delay(3200).fadeOut(300);
        }
    });
    </script>



 </head>
 <body>

 <!-- Start Overlay -->
 <div id="overlay"></div>
 <!-- End Overlay -->
 <!-- Start Special Centered Box -->
 <div id="specialBox">

 TEST Overlay BOX

 </div>

 <!-- Start Special Centered Box -->
  <!-- Start Normal Page Content -->

 <div id="wrapper">        

 Hello World!

 </div>

 </body>

我自己的代码中的错误是同时对两个不同的脚本做同样的事情..如果“Milche Patern”会看到代码比我实现得快得多并且没有浪费时间坚持这个问题是相同的作为我之前的问题或说“每 24 小时一次 = 每天一次”。但我总会找到喜欢浪费时间和浪费我们时间的人

4

0 回答 0