如何将回调附加到对话框显示的 jquery 效果?

发布于 2024-11-27 10:02:35 字数 404 浏览 5 评论 0原文

我的问题是我不知道如何将回调附加到 jquery ui 对话框显示。

显示实际上是一个选项:

$( ".selector" ).dialog({ show: 'slide' });

我想在幻灯片动画完成后进行回调。我从效果本身来看,它们有一个回调:

effect( effect, [options], [speed], [callback] )

但在对话框中,效果的设置非常不同。我也尝试过输入:

$( ".selector" ).dialog({ show: 'slide', callback: function() {} });

但没有成功。

建议?

My problem is that I do not know how to attach callback to the jquery ui dialog show.

The show is actually an option:

$( ".selector" ).dialog({ show: 'slide' });

I want to have a callback after the slide animation is complete. I looked from the effects itself and they have a callback:

effect( effect, [options], [speed], [callback] )

But in the dialog the effect is set up very differently. I tried also putting:

$( ".selector" ).dialog({ show: 'slide', callback: function() {} });

But it didn't work.

Suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

顾北清歌寒 2024-12-04 10:02:36

我发现有必要使用“focus:”事件。由于显示:我失去了正确选择的按钮。可爱的互动。

focus: function( event, ui ) {
    $(this).siblings('.ui-dialog-buttonpane').find("button:contains('Upload')").focus();
},

I found it necessary to use the "focus:" event. I was losing the correctly selected button because of the show:. Lovely interactions.

focus: function( event, ui ) {
    $(this).siblings('.ui-dialog-buttonpane').find("button:contains('Upload')").focus();
},
小女人ら 2024-12-04 10:02:35

更新 2015-07-27 对于使用 jQuery v1.10.0 或更高版本的任何人,请参阅这个其他答案 因为我的解决方案不适用于较新版本的 jQuery。


原始答案

已经回答了,但既然我有了答案,我还是要发布它......

$('#dialog').dialog({
    show: {
        effect: 'slide',
        complete: function() {
            console.log('animation complete');
        }
    },
    open: function(event, ui) {
        console.log('open');
    }
});

在<中显示open,然后是animationcomplete em>控制台

Update 2015-07-27 For anyone using jQuery v1.10.0 or above please see this other answer as my solution will not work with newer versions of jQuery.


Original answer

Already answered but since I had an answer, I'm going to post it anyway…

$('#dialog').dialog({
    show: {
        effect: 'slide',
        complete: function() {
            console.log('animation complete');
        }
    },
    open: function(event, ui) {
        console.log('open');
    }
});

Shows open followed by animation complete in the Console

浴红衣 2024-12-04 10:02:35

两年后,建议的解决方案(由 @andyb)不再适用于当前版本的 jQuery UI(特别是从 v1.10.0 开始)。他的解决方案依赖于complete回调方法——一个未记录的功能。

我想出了一个最新的解决方案,使用 jQuery Promise 对象:

$("#dialog").dialog({
    show: {
        effect: "drop",
        direction: "up",
        duration: 1000
    },
    hide: {
        effect: "drop",
        direction: "down",
        duration: 1000
    },
    open: function () {
        $(this).parent().promise().done(function () {
            console.log("[#Dialog] Opened");
        });
    },
    close: function () {
        $(this).parent().promise().done(function () {
            console.log("[#Dialog] Closed");
        });
    }
});

这是常见的 JSFiddle 演示:http://jsfiddle.net/losnir/jcmpm/

Two years later, the suggested solution (by @andyb) is no longer working in current versions of jQuery UI (specifically since v1.10.0). His solution relied on the complete callback method - an undocumented feature .

I've came up with an up-to-date solution, using jQuery Promise object:

$("#dialog").dialog({
    show: {
        effect: "drop",
        direction: "up",
        duration: 1000
    },
    hide: {
        effect: "drop",
        direction: "down",
        duration: 1000
    },
    open: function () {
        $(this).parent().promise().done(function () {
            console.log("[#Dialog] Opened");
        });
    },
    close: function () {
        $(this).parent().promise().done(function () {
            console.log("[#Dialog] Closed");
        });
    }
});

Here is the usual JSFiddle Demo: http://jsfiddle.net/losnir/jcmpm/

好久不见√ 2024-12-04 10:02:35

我下载了 jquery ui dev 包,发现回调设置为“完整”:

$( ".selector" ).dialog({ show: 'slide', complete: function() {} });

感谢每个试图帮助解决此问题的人:)

I downloaded the jquery ui dev bundle and found out that the callback is set with "complete":

$( ".selector" ).dialog({ show: 'slide', complete: function() {} });

Thanks for everyone trying to help solve this :)

胡渣熟男 2024-12-04 10:02:35

尝试使用对话框的 open 事件:

$( ".selector" ).dialog({
   open: function(event, ui) { ... }
});

Try to use open event of dialog:

$( ".selector" ).dialog({
   open: function(event, ui) { ... }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文