简体   繁体   中英

jQuery-UI Modal overlay

Working with jQuery-UI, I created a 3 button alert for a game I built to add difficulties to it.

When I started writing the script for the alert, the overlay worked fine but now for some reason, it doesn't cover a horizontal strip under the dialog. I am not sure if it's the javascript or the CSS doing this but I need to keep both of them as it is with the full overlay.

jsFiddle example: 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!');
}

Could someone please explain to me why the overlay doesn't cover the whole window.

I'm not familiar with jquery-ui, but if you check the overlay layer on Google Chrome via Developer Tools , you'd see the that jquery-ui applies a white background image to .ui-widget-overlay which is repeated horizontally:

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

So, you could fix that by overriding the background property as follows:

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

ONLINE DEMO .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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