动态选择对jquery-ui-dialog的关闭效果 [英] Dynamically choosing the close effect on a jquery-ui-dialog

查看:109
本文介绍了动态选择对jquery-ui-dialog的关闭效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此对话框:

$("#myDialog").dialog({
    hide: {effect: "fade", duration: 3000},
    buttons: {
        Save: function() {
            $.post(someurl, function() {
                $("#myDialog").dialog( "close" );
            });
        },
        Cancel: function() {
            $("#myDialog").dialog( "close" );
        }
    }
});

我有两个在语义上不同的接近动作:

I have two close actions that are different semantically:

  1. 成功后关闭-在这种情况下,我想慢慢淡出对话框(我还在显示绿色的Vee图标,上面的代码片段中未显示).
  2. 取消后关闭-我想立即使对话框消失,淡入淡出的效果不适用于IMO.

上面的代码在两种情况下都只使用.dialog("close"),因此当然两种情况都具有相同的淡出效果.

The above code just uses .dialog("close") in both cases, so of course both cases get the same fade out effect.

在第二种情况下实现即时关闭,同时在第一种情况下保持缓慢的淡出效果的最佳方法是什么?

What's the best way to achieve instant close on the second case, while retaining the slow fadeout in the first?

编辑:我还希望单击ESCAPE具有与取消"按钮完全相同的效果-即时淡出.

Edit: I also want clicking ESCAPE to have the exact same effect as the Cancel button - instant fade out.

推荐答案

最简单的方法是:

$("#myDialog").dialog({
    hide: null,
    buttons: {
        Save: function() {
            $("#myDialog").dialog("option", "hide", "fade").dialog("close");
        },
        Cancel: function() {
            $("#myDialog").dialog("close");
        }
    },
    close: function(e) {
        $("#myDialog").dialog("option", "hide", null);
    }
});

这篇关于动态选择对jquery-ui-dialog的关闭效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆