这是我到目前为止所拥有的,但它正在立即加载:
<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>
我做错了什么?
答案 0 :(得分:3)
它正在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);
});
答案 1 :(得分:1)
您正在调用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事件 {{ 1}}。