jQuery-UI模态叠加

时间:2014-02-22 05:42:35

标签: javascript jquery css jquery-ui

使用jQuery-UI,我为我构建的游戏创建了一个3按钮提醒,以增加它的难度。

当我开始为警报编写脚本时,叠加层工作正常,但由于某种原因,它现在没有覆盖对话框下的水平条带。我不确定这是javascript还是CSS这样做但是我需要将它们保持为完整叠加层。

jsFiddle示例:http://jsfiddle.net/spedwards/dJVF3/

CSS:

p {
    text-align: center;
}
.no-close .ui-dialog-titlebar-close {
    display: none;
}
.ui-dialog-titlebar.ui-widget-header {
    background: #104f96; /* Old browsers */
    background: -moz-linear-gradient(top,  #104f96 0%, #157dd3 45%, #54abee 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#104f96), color-stop(45%,#157dd3), color-stop(100%,#54abee)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  #104f96 0%,#157dd3 45%,#54abee 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  #104f96 0%,#157dd3 45%,#54abee 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  #104f96 0%,#157dd3 45%,#54abee 100%); /* IE10+ */
    background: linear-gradient(to bottom,  #104f96 0%,#157dd3 45%,#54abee 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#104f96', endColorstr='#54abee',GradientType=0 ); /* IE6-9 */
}
div.ui-widget-content {
    background: #74bbf2;
}
.ui-widget-content, .ui-dialog-titlebar.ui-widget-header {
    border: 1px solid #fff;
}
.ui-state-default {
    border: 1px solid #fff !important;
    background: #539ff5 !important;
    background: -moz-linear-gradient(top,  #539ff5 0%, #78bef8 50%, #6cb7f8 51%, #add9fb 100%) !important;
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#539ff5), color-stop(50%,#78bef8), color-stop(51%,#6cb7f8), color-stop(100%,#add9fb)) !important;
    background: -webkit-linear-gradient(top,  #539ff5 0%,#78bef8 50%,#6cb7f8 51%,#add9fb 100%) !important;
    background: -o-linear-gradient(top,  #539ff5 0%,#78bef8 50%,#6cb7f8 51%,#add9fb 100%) !important;
    background: -ms-linear-gradient(top,  #539ff5 0%,#78bef8 50%,#6cb7f8 51%,#add9fb 100%) !important;
    background: linear-gradient(to bottom,  #539ff5 0%,#78bef8 50%,#6cb7f8 51%,#add9fb 100%) !important;
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#539ff5', endColorstr='#add9fb',GradientType=0 ) !important;
}

使用Javascript:

$(function () {
    $('.diff').click(function (e) {
        e.preventDefault();
        $.ui.dialog.prototype._focusTabbable = function(){};
        var dialog = $('<p>Select your difficulty</p>').dialog({
            resizable: false,
            closeOnEscape: false,
            width: 350,
            modal: true,
            dialogClass: "no-close",
            draggable: false,
            title: 'Difficulty',
            buttons: {
                "Easy": function () {
                    easy();
                    dialog.dialog('destroy');
                },
                    "Normal": function () {
                    normal();
                    dialog.dialog('destroy');
                },
                    "Insane": function () {
                    insane();
                    dialog.dialog('destroy');
                }
            },
            open: function(e, ui) {
                $('button').blur();
            }
        });
    });
});

function easy() {
    alert('You selected Easy');
}

function normal() {
    alert('You selected Normal');
}

function insane() {
    alert('You selected Insane! Good luck!');
}

有人可以向我解释为什么叠加层不会覆盖整个窗口。

1 个答案:

答案 0 :(得分:1)

我不熟悉jquery-ui,但是如果你通过开发人员工具检查Google Chrome上的 overlay 图层,你会看到那个jquery-ui将白色背景图像应用于水平重复的.ui-widget-overlay

.ui-widget-overlay {
    background: #aaaaaa url(images/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x;
    opacity: .3;
    filter: Alpha(Opacity=30);
}

因此,您可以通过覆盖background属性来解决此问题,如下所示:

.ui-widget-overlay {
    background: #aaa !important;
}

<强> ONLINE DEMO