jquery tools overlay, how to keep mask when switching overlays

纵饮孤独 提交于 2019-12-06 05:06:51

I hope you do not mind but I created my own simplified example. Hopefully you will be able to adapt this to your situation.

There is a little bit of flicker between the dialogue boxes (due to the animation effect) but the mask stays in place. I imagine you could remove the flickering by adjusting the animation effect settings - I suspect you could do something in the overlay's onBeforeLoad method but I'm not exactly sure what.

<!DOCTYPE html>
<html>
<head>
    <title>Chained Modals</title>
    <script src="http://cdn.jquerytools.org/1.2.5/full/jquery.tools.min.js"></script>
    <style>
    .modal {
        background-color:#fff;
        display:none;
        width:350px;
        padding:15px;
        text-align:left;
        border:2px solid #333;

        opacity:0.8;
        -moz-border-radius:6px;
        -webkit-border-radius:6px;
        -moz-box-shadow: 0 0 50px #ccc;
        -webkit-box-shadow: 0 0 50px #ccc;
    }
    </style>
</head>
<body>
<p>
    <button class="modalInput" rel="#box1">Stage 1</button>
</p>
<div class="modal" id="box1">
    <h2>Stage 1 dialogue</h2>
    <p>
        You can only interact with elements that are inside this dialog.
        To close it click a button or use the ESC key.
    </p>
    <button class="modalInput" rel="#box2">Stage 2</button>
</div>
<div class="modal" id="box2">
    <h2>Stage 2 dialogue</h2>
    <p>
        You can only interact with elements that are inside this dialog.
        To close it click a button or use the ESC key.
    </p>
    <button class="modalInput" rel="#box3">Stage 3</button>
</div>
<div class="modal" id="box3">
    <h2>Stage 3 dialogue</h2>
    <p>
        You can only interact with elements that are inside this dialog.
        To close it click a button or use the ESC key.
    </p>
    <button class="close">End</button>
</div>
<script>

$(window).load(function() {
var msk;

var triggers = $(".modalInput").overlay({
    mask: {
        color: '#ebecff',
        loadSpeed: 200,
        opacity: 0.9,
        onClose: function() {
            var id = this.getExposed().attr('id');
            if(id == 'box1'|| id == 'box2'){
               var nextId;
               if(id == 'box1'){
                  nextId = '#box2';
               }
               if(id == 'box2'){
                  nextId = '#box3';
               }
               msk = this.getMask();
               msk.css('display','block');
               $(nextId).css('z-index', '9999');
            }
        }
    },
    closeOnClick: false,
    onBeforeLoad: function(){
        var id = this.getOverlay().attr('id');
        if(id == 'box2'|| id == 'box3'){
               // need to put something here to avoid flicker
               //
           // this.getConf().mask.startOpacity = 0.8; 
        }
    }
});

});
</script>
</body>
</html>

I hope this helps.

I think an easier way would be to

.overlay({
   mask: { color: '#000', opacity: '.60' },
   onLoad: function(){
       var t = $.mask;
       if(!t.isLoaded()){
            t.load();
            var ov = this.getOverlay();
            ov.css('z-index', '9999');
       }
   }
});

You can add "closeSpeed: 0" into mask configuration of the first overlay and it will work. For example:

    $('#login_overlay').overlay({
        top:'center',
        mask: {
            color: '#666',
            closeSpeed: 0,
            opacity: 0.5
        }
    });

An alternative is to handle separately the mask: the overlay is created without a mask, and the mask is activated separately.

Your first overlay would require a setup such as:

$(selector).overlay({ 
    ..., 
    onBeforeLoad: function(){
                       $(document).mask('#222'); 
                       closeMask=true;
                  },
    onClose: function(){
                       if (closeMask) $.mask.close();
                  }
);

Then, in order to show the second overlay, you set the closeMask variable to false. Obviously, the second overlay must hide the mask on close.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!