Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI dialog overlay - how to set different background colors for different dialogs

I have used different jQuery dialogs. For some dialogs I want a transparent background. If I change the background CSS in the .ui-widget-overlay class then it will apply to all the dialogs.

How to set different background colors for different dialogs?

like image 490
shaz Avatar asked Dec 11 '09 08:12

shaz


2 Answers

Just create a style like the following and use the dialogClass option on those dialogs you want to have a transparent background. Of course you can make multiple styles and pass in whatever you want

<style type="text/css" media="screen">
    .transparent { background:transparent }
</style>

//make dialog with transparent background
$("#dialog").dialog({dialogClass:'transparent'});
//make default dialog
$("#dialog2").dialog();

Check demo site: http://jsbin.com/ifoja (basic jquery, jquery ui, jquery ui css + custom css transparent class)

like image 98
jitter Avatar answered Nov 15 '22 12:11

jitter


There is only one overlay for all jQuery widgets. Therefor we have to change it's opacity on demand:

var overlayOpacityNormal = 0.3, overlayOpacitySpecial = 0;
$('#idOfDlg').dialog({
    modal: true,
    open: function()
    {
        overlayOpacityNormal = $('.ui-widget-overlay').css('opacity');
        $('.ui-widget-overlay').css('opacity', overlayOpacitySpecial);
    },
    beforeClose: function()
    {
        $('.ui-widget-overlay').css('opacity', overlayOpacityNormal);
    }
});
like image 41
Ronny Sherer Avatar answered Nov 15 '22 14:11

Ronny Sherer