简体   繁体   English

如何创建非模态引导对话框

[英]how to create a non-modal bootstrap dialog box

I am trying to create a non-modal bootstrap dialog box.我正在尝试创建一个非模态引导对话框。 I just don't know how to do it.我只是不知道该怎么做。 I have checked lot of post but none answers my question.我检查了很多帖子,但没有一个回答我的问题。 I need the dialog to be none - modal because I want the user to be able to do other things even if the dialog box is opened.我需要对话框是无 - 模态的,因为我希望用户即使打开对话框也能够做其他事情。

I saw a link https://snippet.run/x657 but when I tried it, didn't work for me.我看到一个链接https://snippet.run/x657但是当我尝试它时,它对我不起作用。 The dialog refused to open对话框拒绝打开

Thanks a lot.非常感谢。

Based on the docs this doesnt appear to be possible - however an alert might serve your purposes: http://getbootstrap.com/javascript/#alerts The alert can be put into a div that has a fixed positioned to keep them visible and independent of the content beneath them.根据文档,这似乎是不可能的 - 但是警报可能会满足您的目的: http : //getbootstrap.com/javascript/#alerts警报可以放入具有固定位置的 div 中,以保持它们的可见性和独立性他们下面的内容。

Fiddle小提琴

The html: html:

<button id="myBtn">show 'modal' alert</button>

<p>
  more content that the user should be able to see....
</p>
<p>
  more content that the user should be able to see....
</p>
<p>
  this is the bottom
</p>

<div style="position:fixed;bottom:0;left:0;width:100%;" id="alerts"></div>

and the JS to add the 'modal' alert (which you can style however you like):和 JS 添加“模态”警报(您可以随意设置样式):

$("#myBtn").click(function() {
    $('<div class="alert alert-success alert-dismissable">'+
            '<button type="button" class="close" ' + 
                    'data-dismiss="alert" aria-hidden="true">' + 
                '&times;' + 
            '</button>' + 
            'modal info...' + 
         '</div>').appendTo("#alerts");
}); 

Just execute the following line once the modal is shown显示模态后只需执行以下行

$(document).off('focusin.bs.modal');

By example :举例:

$("#my-modal").on('shown.bs.modal',function(){
    $(document).off('focusin.bs.modal');
});

You want the user to be able to do other things even if the dialog box is opened , try to inspect element that dialog box .You will notice a div with class "modal-backdrop in" is being applied just before this dialog box div .您希望用户即使打开对话框也能够做其他事情,请尝试检查该对话框的元素。您会注意到在此对话框 div 之前应用了一个带有“modal-backdrop in”类的 div。 Due to this class only the body content seems to freeze and you won't be able to click anywhere else in the document body .Remove this class and let user click anywhere and do whatever he wants in the DOM element .由于这个类,只有正文内容似乎冻结,您将无法单击文档正文中的任何其他地方。删除这个类,让用户单击任何地方并在 DOM 元素中执行他想做的任何事情。

Bootstrap 3 provides a parameter called backdrop that when set to static prevents the dialog from closing when clicked outside. Bootstrap 3提供了一个名为背景的参数,当设置为静态时,可防止对话框在外部单击时关闭。

$('#myModal').modal({
  backdrop: 'static'
})

I solved it like that:我是这样解决的:

I created a modal-dialog without "modal" container:我创建了一个没有“模态”容器的模态对话框:

<div class="modal-dialog" id="popup_tool_mouseposition" data-backdrop="false" style="display: none;">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">
                <span>&times;</span>
            </button>
            <h4 class="modal-title" data-i18n="tool.mouseposition.title"></h4>
        </div>
        <div class="modal-body">HUHU</div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal" data-i18n="com.close"></button>
        </div>
    </div>
</div>

and now i stylied it like that... very cruel at this moment... i'll fix that later现在我把它设计成那样......此刻非常残酷......我稍后会解决这个问题

$("#popup_tool_mouseposition").show();
$("#popup_tool_mouseposition").draggable({
    handle : ".modal-header"
});
$("#popup_tool_mouseposition").width(300);
$("#popup_tool_mouseposition").css('position', 'fixed');
$("#popup_tool_mouseposition").css('top', '0');
$("#popup_tool_mouseposition").css('left', '0');

draggable() comes from jqueryUI draggable() 来自 jqueryUI

    .modal-backdrop{
        display:none !important;
    }

css css

// hide backdrop overlay:
.modal-backdrop {
    display: none !important;
}

// allow scroll
.modal,
.modal-open {
    overflow-y: auto;

    padding-right: 0 !important;
}

// place popup in the center, allow interaction with page under popup
.modal {
    top: 50%;
    right: auto;
    bottom: auto;
    left: 50%;

    transform: translate(-50%,-50%);
}

.modal-dialog {
    margin: 0 !important;
}

// change animation
.modal.fade .modal-dialog {
    transform: scale(.1, .1);
}

.modal.in .modal-dialog {
    transform: scale(1, 1);
}

js js

// save focus and scroll position on popup close (otherwise button that triggered popup will take focus)
$(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) {
  var $this   = $(this);
  var href    = $this.attr('href');
  var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))); // strip for ie7

  $target.off('hidden.bs.modal');
});

// allow interaction with page under popup
$('.modal').on('shown.bs.modal', function(){
  $(document).off('focusin.bs.modal');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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