简体   繁体   English

jQuery UI模式对话框覆盖淡出

[英]jQuery UI modal dialog overlay fade out

Is it possible to apply a fade out effect on the jQuery UI modal dialog box overlay? 是否可以在jQuery UI模式对话框覆盖上应用淡出效果? The issue is that the overlay div is destroyed when the modal dialog box is closed preventing any kind of animation. 问题是当关闭模态对话框时,会破坏叠加div,从而阻止任何类型的动画。 This is the code I have that would work if the overlay div was not destroyed on close. 这是我有的代码,如果覆盖div没有在关闭时销毁。

$("#edit-dialog-box").dialog(
{
    autoOpen: false,
    modal: true,
    width: "30em",
    show: "fade",
    hide: "fade",
    open: function()
    {
        $(".ui-widget-overlay").hide().fadeIn();
    },
    close: function()
    {
        $(".ui-widget-overlay").fadeOut();
    }
});

Demo: http://jsfiddle.net/276Ft/2/ 演示: http//jsfiddle.net/276Ft/2/

$('#dialog').dialog({
    autoOpen: true,
    modal: true,

    width: '100px',
    height: '100px',

    show: 'fade',
    hide: 'fade',

    open: function () {
        $('.ui-widget-overlay', this).hide().fadeIn();

        $('.ui-icon-closethick').bind('click.close', function () {
            $('.ui-widget-overlay').fadeOut(function () {
              $('.ui-icon-closethick').unbind('click.close');
              $('.ui-icon-closethick').trigger('click');
            });

            return false;
        });
    }
});

I advise not to bind the fadeOut of the overlay to the “closethick” close event. 我建议不要将叠加层的fadeOut绑定到“closethick”关闭事件。
This solution will work in all cases, for example if you use a “Cancel” button, or if the dialog closes itself after doing anything else due to other buttons: 此解决方案适用于所有情况,例如,如果您使用“取消”按钮,或者由于其他按钮而在执行任何其他操作后对话框自行关闭:

$('#dialog').dialog({
    autoOpen: true,
    modal: true,

    width: '100px',
    height: '100px',

    show: 'fade',
    hide: 'fade',

    open: function () {
        $('.ui-widget-overlay', this).hide().fadeIn();
    },

    beforeClose: function(event, ui){
        // Wait for the overlay to be faded out to try to close it again
        if($('.ui-widget-overlay').is(":visible")){
            $('.ui-widget-overlay').fadeOut(function(){
                $('.ui-widget-overlay').hide();
                $('.ui-icon-closethick').trigger('click');
            });
            return false; // Avoid closing
        }
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM