关于Fancybox关闭的Div亮点 - Jquery

时间:2011-10-25 22:57:15

标签: jquery fancybox

我正在尝试在我的Fancybox关闭时添加一个setTimeout函数。当我尝试这个时,代码中断了。谁能告诉我我做错了什么?

<script type="text/javascript">
$(document).ready(function(){

$(".popFrame").fancybox({
'height'    : 600,
'autoScale' : false,
'transitionIn'    : 'elastic',
'transitionOut'   : 'elastic',
'speedIn'     :   600,
'speedOut'      :   200,
'type'  : 'iframe',
'scrolling' : 'no',
'autoDimensions'    :   false,
'width'   :   620,
'hideOnContentClick' : false, 
'onClosed':function(){
$('#hidden').load('file.php');
}
setTimeout(function(){
$("div.color").fadeOut("slow", function () {
$("div.color").remove();
});
}, 
4000);
);
;})
</script>

我得到的错误是:

missing } after property list
[Break On This Error] setTimeout(function(){

4 个答案:

答案 0 :(得分:1)

您的代码中存在一些语法错误:

$(document).ready(function(){

    $(".popFrame").fancybox({
        'height'    : 600,
        'autoScale' : false,
        'transitionIn'    : 'elastic',
        'transitionOut'   : 'elastic',
        'speedIn'     :   600,
        'speedOut'      :   200,
        'type'  : 'iframe',
        'scrolling' : 'no',
        'autoDimensions'    :   false,
        'width'   :   620,
        'hideOnContentClick' : false, 
        'onClosed':function(){
            $('#hidden').load('file.php');  
            setTimeout(function(){
                $("div.color").fadeOut("slow", function () {
                    $("div.color").remove();
                });
            },4000);
        }
    });

});

我希望这会有所帮助。

答案 1 :(得分:0)

这一行有额外的分号:

});

答案 2 :(得分:0)

您在调用onClosed之前已经立即终止了setTimeout函数,因此您将收到语法错误。尝试在函数

中移动setTimeout代码

答案 3 :(得分:0)

您可以使用jsLint来调试此类内容。当你有数千行JS时,特别有用。以下是它为您的代码所说的内容(在打开所有“容忍”选项后):

Error:
Problem at line 18 character 1: Expected '}' to match '{' from line 3 and instead 
saw 'setTimeout'.

setTimeout(function(){

Problem at line 23 character 6: Expected ')' to match '(' from line 3 and instead saw ';'.

4000);

Problem at line 23 character 7: Expected ';' and instead saw ')'.

4000);

Problem at line 24 character 1: Expected an identifier and instead saw ')'.

);

当然,在修复这些错误时,您需要在外部编辑器中打开包含行号的JavaScript代码。

相关问题