0

好吧,我知道如何显示可关闭的置顶消息,但我想知道如何让它在 10 秒后关闭,并显示 10 秒计数器……以及如何赋予它悬停效果……这是我的可关闭置顶留言,仅供参考

<script>
function closeBox(toClose) {
    document.getElementById(toClose).style.display = "none";setCookie(toClose,closed", 20);}

function setCookie(cName, value, expiredays) {var expDate = new Date();expDate.setDate(expDate.getDate()+expiredays);document.cookie=cName + "=" + escape(value) + ";expires=" + expDate.toGMTString();}

    function loadMsg(msgClass) {msg = document.getElementsByTagName("div");for (i=0; i<msg.length; i++){if(msg[i].className == msgClass) {if(document.cookie.indexOf(msg[i].id) == -1) {msg[i].style.display = "block";}}}}

    window.onload=function(){loadMsg('msgbox'); }
</script>

    http://kownleg.blogspot.com
    <style>
    div.guestwarn {
    background:#000000;
    color:#FFFFFF;
    max-width:280px;min-height:18px;padding:0 5px 3px;position:fixed;right: 2%;
        top: 50%;padding: 10px 15px;position: fixed;z-index: 10;font-size:12px;-moz-border-radius: 8px; -webkit-border-radius: 8px;  filter:alpha(opacity=88);
        -moz-opacity:.88; opacity:.88; -moz-box-shadow:5px 5px 5px #191919; -webkit-box-shadow:5px 5px 5px #191919; box-shadow:5px 5px 5px #191919;
    }
    .close {float: right;background: transparent url(http://1.bp.blogspot.com/-hMdL9UJje_c/UA7nJADBTSI/AAAAAAAAABU/S5zftNPRxfs/s1600/close.png);width: 22px;height: 22px;}
     </style> 


 <div id="message-1" class="msgbox" style="display: none;">
    <div class="guestwarn"><a href="#" class="close" onclick="closeBox('message-1');   return false;" title=""></a>
**My Sticky Text Is Here**
    </div>
 </div>
4

3 回答 3

1

已经有很多为此构建的插件,我更喜欢Purr,另一个我知道的是jQuery Growl

于 2012-10-01T17:49:01.707 回答
1

您可以使用 jquerydelay()函数简单地执行此操作。

$("#message-1").live("click",function(){
        $(".guestwarn").show('slow');
        // show the counter
         $(".guestwarn").delay(10000).hide("slow");
          return false;
        });
于 2012-10-01T18:08:08.233 回答
0

在脚本末尾添加这一行:

setTimeout(function(){closeBox('message-1')}, 10000);
于 2012-10-01T17:44:34.263 回答