开发者

Adding jQuery UI breaks jQuery show()

开发者 https://www.devze.com 2023-01-12 23:53 出处:网络
I have some jQuery code that runs fine until I add the jQuery UI library (1.7.2) and this causes the show() method to fail when I specify a callback.

I have some jQuery code that runs fine until I add the jQuery UI library (1.7.2) and this causes the show() method to fail when I specify a callback.

$('#main.home ul#promotions').show(function() {
    if (typeof f == "function") f();
});

It would seem that jQuery UI overrides show and now I need to specify an additional parameter for "effect", the following code fixes the issue:

$('#main.home ul#promotions').show('blind', function() {
    if (typeof f == "function") f();
});

However this is part of a script that shouldn开发者_Python百科't be dependent on the jQuery UI library so ideally I want to stop jQuery UI overriding show in this case.

Can anyone suggest how this can be done?

Dave


The normal jQuery .show() method doesn't take a single function argument. It takes either no arguments, or a duration and an (optional) callback. Thus the jQuery UI version is compatible.

For plain jQuery, if you're interested in having .show() happen immediately, I think you can pass a null zero as the first argument. However, I don't see why you'd do that; if you don't want to animate then .show() is synchronous, and you can just put your "callback" code right after calling it. In other words, there's no point to a callback in that case.

edit — as the boundlessly knowledgeable Mr Craver points out, a call to .show() with just a function is like calling it with .show("normal", theFunction). It's unfortunate that the jQuery UI code apparently messes that up, but you can code with "normal" as the first argument and you should be OK.

0

精彩评论

暂无评论...
验证码 换一张
取 消