首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >多模态叠加

多模态叠加
EN

Stack Overflow用户
提问于 2013-10-11 04:41:39
回答 27查看 300.4K关注 0票数 226

我需要的是覆盖显示上面的第一个模式,而不是在后面。

代码语言:javascript
复制
$('#openBtn').click(function(){
	$('#myModal').modal({show:true})
});
代码语言:javascript
复制
<a data-toggle="modal" href="#myModal" class="btn btn-primary">Launch modal</a>

<div class="modal" id="myModal">
	<div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
          <h4 class="modal-title">Modal title</h4>
        </div><div class="container"></div>
        <div class="modal-body">
          Content for the dialog / modal goes here.
          <br>
          <br>
          <br>
          <br>
          <br>
          <a data-toggle="modal" href="#myModal2" class="btn btn-primary">Launch modal</a>
        </div>
        <div class="modal-footer">
          <a href="#" data-dismiss="modal" class="btn">Close</a>
          <a href="#" class="btn btn-primary">Save changes</a>
        </div>
      </div>
    </div>
</div>
<div class="modal" id="myModal2" data-backdrop="static">
	<div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
          <h4 class="modal-title">Second Modal title</h4>
        </div><div class="container"></div>
        <div class="modal-body">
          Content for the dialog / modal goes here.
        </div>
        <div class="modal-footer">
          <a href="#" data-dismiss="modal" class="btn">Close</a>
          <a href="#" class="btn btn-primary">Save changes</a>
        </div>
      </div>
    </div>
</div>


<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.0/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.0/js/bootstrap.min.js"></script>

我试图更改.modal-backdropz-index,但它变得一团糟。

在某些情况下,我在同一页上有两个以上的情态动词。

EN

回答 27

Stack Overflow用户

发布于 2014-02-17 05:18:32

我意识到答案已经被接受,但我强烈建议不要通过黑客引导来解决这个问题。

您可以很容易地通过挂钩shown.bs.modal和hidden.bs.modal事件处理程序并调整那里的z索引来达到相同的效果。

Here's a working example

有关更多信息,请访问available here.

此解决方案自动与任意深度堆栈的模态一起工作。

脚本源代码:

代码语言:javascript
复制
$(document).ready(function() {

    $('.modal').on('hidden.bs.modal', function(event) {
        $(this).removeClass( 'fv-modal-stack' );
        $('body').data( 'fv_open_modals', $('body').data( 'fv_open_modals' ) - 1 );
    });

    $('.modal').on('shown.bs.modal', function (event) {
        // keep track of the number of open modals
        if ( typeof( $('body').data( 'fv_open_modals' ) ) == 'undefined' ) {
            $('body').data( 'fv_open_modals', 0 );
        }

        // if the z-index of this modal has been set, ignore.
        if ($(this).hasClass('fv-modal-stack')) {
            return;
        }

        $(this).addClass('fv-modal-stack');
        $('body').data('fv_open_modals', $('body').data('fv_open_modals' ) + 1 );
        $(this).css('z-index', 1040 + (10 * $('body').data('fv_open_modals' )));
        $('.modal-backdrop').not('.fv-modal-stack').css('z-index', 1039 + (10 * $('body').data('fv_open_modals')));
        $('.modal-backdrop').not('fv-modal-stack').addClass('fv-modal-stack'); 

    });        
});
票数 89
EN

Stack Overflow用户

发布于 2014-09-23 03:38:43

结合A1rPun的回答和StriplingWarrior的建议,我得出了以下结论:

代码语言:javascript
复制
$(document).on({
    'show.bs.modal': function () {
        var zIndex = 1040 + (10 * $('.modal:visible').length);
        $(this).css('z-index', zIndex);
        setTimeout(function() {
            $('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack');
        }, 0);
    },
    'hidden.bs.modal': function() {
        if ($('.modal:visible').length > 0) {
            // restore the modal-open class to the body element, so that scrolling works
            // properly after de-stacking a modal.
            setTimeout(function() {
                $(document.body).addClass('modal-open');
            }, 0);
        }
    }
}, '.modal');

甚至适用于事后添加的动态模态,并消除了第二个滚动条问题。最值得注意的是,我发现这样做很有用,那就是将modals中的表单与来自Bootbox警报的验证反馈集成在一起,因为它们使用动态modals,因此需要您将事件绑定到文档而不是.modal,因为这只会将其附加到现有的modals。

Fiddle here.

票数 27
EN

Stack Overflow用户

发布于 2014-04-16 00:19:51

基于Yermo Lamers的建议的更短的版本,这似乎工作得很好。即使有基本的动画,如淡入/淡出,甚至疯狂的蝙蝠侠,报纸旋转。http://jsfiddle.net/ketwaroo/mXy3E/

代码语言:javascript
复制
$('.modal').on('show.bs.modal', function(event) {
    var idx = $('.modal:visible').length;
    $(this).css('z-index', 1040 + (10 * idx));
});
$('.modal').on('shown.bs.modal', function(event) {
    var idx = ($('.modal:visible').length) -1; // raise backdrop after animation.
    $('.modal-backdrop').not('.stacked').css('z-index', 1039 + (10 * idx));
    $('.modal-backdrop').not('.stacked').addClass('stacked');
});
票数 26
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19305821

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档