jQuery UI: How to use ui-widget-overlay by itself?

后端 未结 9 1634
独厮守ぢ
独厮守ぢ 2020-12-12 23:13

I am trying to create an overlay, similar to the one that jQuery UI Dialog uses. I can create the overlay like this:

var $overlay = $(\'
相关标签:
9条回答
  • 2020-12-12 23:20

    As of jQuery 1.4.4, it looks like it's as easy as:

    $.ui.dialog.overlay.create();
    

    Update

    Here is a fiddle.

    The code above returns the HTML element, so it should be use like this:

    $("body").append($.ui.dialog.overlay.create());
    

    Update 2

    As was said, this doesn't work in jquery 1.10. To fix this, I created my own overlay:

    <div id="loading" style="display: none;">   
        <div class="loading-container">         
            <img src="/img/loading.gif"/>
        </div>                                  
    </div>                                      
    

    (the image is just a random image I wanted to display in the middle to indicate that the page was loading) Then I added this CSS:

    /* loading overlays */       
    #loading {                   
        position: fixed;         
        top: 0;                  
        left: 0;                 
        width: 100%;             
        height: 100%;            
        background-color: #000;  
        filter:alpha(opacity=50);
        -moz-opacity:0.5;        
        -khtml-opacity: 0.5;     
        opacity: 0.5;            
        z-index: 10000;          
    }                            
    .loading-container {         
        position:fixed;          
        top: 50%;                
        left: 50%;               
    }                            
    

    Then one can call $('#loading').show() and $('#loading').hide() to hide and remove it.

    I had to tweak the answer here: stack overflow response

    0 讨论(0)
  • 2020-12-12 23:22

    this will work better for weird screens or with framesets :

    var overlay = $('<div class="ui-overlay"  style="position: absolute; top: 0pt; left: 0pt; display: inline-block; overflow: hidden;"><div class="ui-widget-overlay" style="top: 0pt; left: 0pt; width: 9999px; height: 99999px;"></div></div>').hide().appendTo($('body'));
    $(overlay).width('100%');
    $(overlay).height('100%');
    $(overlay).fadeIn();
    

    check it out: http://jsfiddle.net/techunter/MdjBr/6/

    0 讨论(0)
  • 2020-12-12 23:24

    Check that: var $dial=$(''); $dial.dialog({modal:true}); $('.ui-dialog').hide();

    0 讨论(0)
  • 2020-12-12 23:26

    Here's a thought for your CSS:

    .ui-widget-overlay { 
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
    
      background-color: #444;
    
      /* add some opacity here */
    } 
    
    0 讨论(0)
  • 2020-12-12 23:27

    You could do something like this:

    <style type="text/css">
        * {border:0;margin:0}
    .ui-widget-overlay {
        background: repeat-x scroll 50% 50% #AAA;
        opacity:0.3;
    }
    
    .ui-widget-overlay {
        height:100%;
        left:0;
        position:absolute;
        top:0;
        width:100%;
    }
    
    </style>
    <script type="text/javascript">
    
        $(function () {
            var $overlay = $('<div class="ui-overlay"><div class="ui-widget-overlay"></div></div>').hide().appendTo('body');
            $overlay.fadeIn();
    
            $(window).resize(function () {
                $overlay.width($(document).width());
                $overlay.height($(document).height());
            });
        });
    </script>
    
    0 讨论(0)
  • 2020-12-12 23:28

    It's very simple, to create overlay just use this code:

    var overlay = new $.ui.dialog.overlay();
    

    and when you have to destroy it use this code:

    overlay.destroy();
    
    0 讨论(0)
提交回复
热议问题