UIkit上的其他模态中的模态

时间:2015-07-01 11:23:35

标签: modal-dialog uikit

当我点击第二个模态时,第一个模态消失。但是,我也想保持开放!这是禁用该行为的方法吗?

我还注意到其他框架(如Foundation)具有相同的行为。

这是我的代码:

<a href="#my-id" data-uk-modal>Open Modal</a>
<div id="my-id" class="uk-modal">
    <div class="uk-modal-dialog"> 
        <a class="uk-modal-close uk-close"></a>
        <p>Lorem ipsum...</p> 
        <a href="#my-id2" data-uk-modal>Nested Modal</a>
    </div>
</div>
<div id="my-id2" class="uk-modal">
    <div class="uk-modal-dialog"> 
        <a class="uk-modal-close uk-close"></a>
        <p>Lorem ipsum...</p>
    </div>
</div>

请参阅jsfiddle demo

5 个答案:

答案 0 :(得分:3)

来自文档:

  

您可以在当前模态中触发新模态。当第二个模态打开时,默认行为将关闭第一个模态。您可以通过添加data-uk-modal="{target:'#ID',modal:false}"属性来阻止这种情况发生。

类似于:

<div>
    <h2>Multiple Modal</h2>
    <button class="uk-button" data-uk-modal="{target:'#modal1', modal: false}">Open Modal 1</button>

</div>

<!-- This is the modal 1-->
<div id="modal1" class="uk-modal">
    <div class="uk-modal-dialog">
        <h2>Modal 1</h2>
        <button class="uk-button" data-uk-modal="{target:'#modal2', modal: false}">Open Modal 2</button>      
    </div>
</div>


<!-- This is the modal 2-->
<div id="modal2" class="uk-modal">
    <div class="uk-modal-dialog">
        <h2>Modal 2</h2>
        <a class="uk-modal-close" href="#">Close Modal 2</a>
    </div>
</div>

应该有用。

我使用javascript:

var modal1 = UIkit.modal("#modal1", {center: true, modal: false}),
    modal2 = UIkit.modal("#modal2", {modal: false});

答案 1 :(得分:3)

您可以使用uk-modal="stack: true"

显示多个模态

这是代码

<button class="uk-button uk-button-default uk-margin-small-right" type="button" data-uk-toggle="target: #modal-example-1">Open</button>

<!-- This is the Parent modal -->
<div id="modal-example-1" uk-modal>
    <div class="uk-modal-dialog uk-modal-body">
        <h2 class="uk-modal-title">Parent Modal</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
        <p class="uk-text-right">
            <button class="uk-button uk-button-default uk-modal-close" type="button">Cancel</button>
            <button class="uk-button uk-button-primary" type="button">Save</button>
        </p>
        <button class="uk-button uk-button-default uk-margin-small-right" type="button" data-uk-toggle="target: #modal-example-2">Open</button>
    </div>
</div>

<!-- This is the Child modal -->
<div id="modal-example-2" uk-modal="stack: true">
    <div class="uk-modal-dialog uk-modal-body">
        <h2 class="uk-modal-title">Child Modal</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </div>
</div>

答案 2 :(得分:1)

你做了一些改变:

您的HTML代码:

<a href="#my-id" data-uk-modal >Open Modal</a>
<div id="my-id" class="uk-modal">
    <div class="uk-modal-dialog"> 
        <a class="uk-modal-close uk-close"></a>
        <p>Lorem ipsum...</p> 
        <a href="#my-id2" data-uk-modal>Nested Modal</a>
    </div>
</div>
<div id="my-id2" class="uk-modal">
    <div class="uk-modal-dialog"> 
        <a class="uk-modal-close uk-close"></a>
        <p>Lorem ipsum...</p>
    </div>
</div>

你的jQuery代码应该是:

$(document).ready(function(){

    $.UIkit.modal('#my-id').show();
    $.UIkit.modal('#my-id2').show();  

});

这应该有效

答案 3 :(得分:0)

我发布了有效的新代码,所以请尝试一下:它会起作用

<div class="popover" >
    <div class="arrow"></div>
    <h3 class="popover-title"><strong>Heading 2</strong></h3>
    <div class="popover-content">
       pop content 2
    </div>
</div>  

这应该有用......

答案 4 :(得分:0)

如果您使用JQuery打开Modals,则要覆盖两个Modallayer,请在Uikit3中使用以下代码:

UIkit.modal(“#yourmodalid”,{center:true,stack:true})。show();

这将使第一个Modallayer打开。