繁体   English   中英

jQuery UI模式对话框覆盖淡出

[英]jQuery UI modal dialog overlay fade out

是否可以在jQuery UI模式对话框覆盖上应用淡出效果? 问题是当关闭模态对话框时,会破坏叠加div,从而阻止任何类型的动画。 这是我有的代码,如果覆盖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();
    }
});

演示: 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;
        });
    }
});

我建议不要将叠加层的fadeOut绑定到“closethick”关闭事件。
此解决方案适用于所有情况,例如,如果您使用“取消”按钮,或者由于其他按钮而在执行任何其他操作后对话框自行关闭:

$('#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