簡體   English   中英

如何在頁面加載后5秒鍾顯示Colorbox?

[英]How do I get Colorbox to display 5 seconds after the page loads?

這是我到目前為止,但它立即加載:

<script type="text/javascript">
var pid = <?php echo $_GET['id']; ?>;
var rlink = "<?php echo $domain; ?>share.php?pid=" + pid;
$(document).ready(function(){
    setTimeout($(".url_tag_small").colorbox({ href: rlink, width: "620px", height: "354px", opacity: 0.0, transition: "none", initialWidth: "620px", initialHeight: "354px", iframe: true, title: true, open: true}), 5000);
});
</script>

我究竟做錯了什么?

它在初始化setTimeout調用時執行回調,而不是在定時器關閉時執行。 把它改成這個:

var pid   = <?php echo $_GET['id']; ?>,
    rlink = "<?php echo $domain; ?>share.php?pid=" + pid;

$(document).ready(function(){
    setTimeout(function(){
      $(".url_tag_small").colorbox({ 
        href: rlink, 
        width: "620px", 
        height: "354px", 
        opacity: 0.0, 
        transition: "none", 
        initialWidth: "620px", 
        initialHeight: "354px", 
        iframe: true, 
        title: true, 
        open: true
      })
    }, 5000);
});

您在調用setTimeout調用該函數而不是將其引用到將打開顏色框的函數。

$(document).ready(function(){
    setTimeout(function() {
      $(".url_tag_small").colorbox({ href: rlink, width: "620px", height: "354px", opacity: 0.0, transition: "none", initialWidth: "620px", initialHeight: "354px", iframe: true, title: true, open: true})
    }, 5000);

});

基本上,你的版本,而不是傳遞一個函數來說,“這是我希望你在5000毫秒后做的事情”,編碼調用.colorbox 之前調用setTimeout

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM