jQuery Fancybox onComplete 功能未运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10816130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 09:48:42  来源:igfitidea点击:

Fancybox onComplete function not running

jqueryfancybox

提问by Claire

For some reason it's just not running the onCompletefunction. It does however load the fancybox div. My html:

出于某种原因,它只是没有运行该onComplete功能。但是它确实加载了fancybox div。我的html:

<ul>
    <li class="orange">

           #1 <a href="#text">click here</a>

           <div id="text" class="text">text text text</div>

    </li>
</ul>

My jquery:

我的jQuery:

 jQuery('li a').fancybox({       
    'autoDimensions':   'false',
    'width' :   631,
    'height':   256,        
    'onComplete':function(){

        alert('running');
        jQuery('.fancybox-skin').css('background-color',colour);
    }
});

the alert doesn't run. I've also tried changing the event function to onClosedand the other events, and nothing.

警报不运行。我还尝试将事件函数更改为onClosed和其他事件,但什么也没有。

回答by JFK

I guess you forgot to specify what version of fancybox you are using.

我猜您忘记指定您使用的是哪个版本的fancybox。

onCompleteis a callback option for fancybox v1.3.x while the fancybox-skinclasswas introduced until version 2.x, ..... so I assume that you are using version 2.x, aren't you?

onComplete是fancybox v1.3.x 的回调选项,而fancybox-skin该类是在2.x 版之前引入的,..... 所以我假设您使用的是2.x 版,不是吗?

Fancybox v2.x options are new and not compatible with previous versions; the equivalent for the onComplete(v1.3.x) option is now the afterLoad(v2.x) callback option.

Fancybox v2.x 选项是新的,与以前的版本不兼容;onComplete(v1.3.x) 选项的等效项现在是afterLoad(v2.x) 回调选项。

Check http://fancyapps.com/fancybox/#docsfor the complete list of options, methods and callbacks for fancybox v2.x

查看http://fancyapps.com/fancybox/#docs以获取fancybox v2.x 的选项、方法和回调的完整列表

回答by Junaid Bhura

afterShowI think is the proper equivalent to onCompletein Fabxybox 2

afterShow我认为是onCompleteFabxybox 2 中的正确等价物

回答by Dre Williams

Fancybox version 2 does not support onComplete. It uses afterLoad.

Fancybox 版本 2 不支持onComplete. 它使用afterLoad.

jQuery('#tips li a').fancybox({       
    'autoDimensions':   'false',
    'width' :   631,
    'height':   256,        
    afterLoad:function(){

        alert('running');
        jQuery('.fancybox-skin').css('background-color',colour); // colour to 'red' for example. typo
    }

});

回答by agriboz

seems like Typo

好像是打字错误

jQuery('#tips li a').fancybox({       
'autoDimensions':   'false',
'width' :   631,
'height':   256,        
'onComplete':function(){

    alert('running');
    jQuery('.fancybox-skin').css('background-color',colour); // colour to 'red' for example. typo
}
});

Working example

工作示例

回答by jobima

Use afterLoadinstead of onComplete

使用afterLoad而不是onComplete