跳过到主要内容

文档

模态框

创建具有不同样式和过渡的模态对话框。

用法

模态框组件由一个叠加层、一个对话框和一个可选的关闭按钮组成。您可以使用任何元素来切换模态对话框。要启用必要的 JavaScript,请添加 uk-toggle 属性。一个 <a> 元素需要链接到模态框的 id。如果您使用的是其他元素,例如按钮,只需添加 uk-toggle="target: #ID" 属性来指定模态框容器的 id。

<div> 元素添加 uk-modal 属性以创建模态框容器和一个遮蔽页面的叠加层。务必添加一个 id 来指示用于切换的元素。使用以下类来定义模态框的部分。

描述
.uk-modal-dialog 将此类添加到子 <div> 元素以创建对话框
.uk-modal-body 添加此类以在模态框及其内容之间创建填充。
.uk-modal-title 将此类添加到标题元素以创建模态框标题。
.uk-modal-close 将此类添加到 <a><button> 元素以创建一个关闭按钮并启用其功能。
<!-- This is a button toggling the modal -->
<button uk-toggle="target: #my-id" type="button"></button>

<!-- This is the modal -->
<div id="my-id" uk-modal>
    <div class="uk-modal-dialog uk-modal-body">
        <h2 class="uk-modal-title"></h2>
        <button class="uk-modal-close" type="button"></button>
    </div>
</div>
  • 打开
  • <!-- This is a button toggling the modal -->
    <button class="uk-button uk-button-default uk-margin-small-right" type="button" uk-toggle="target: #modal-example">Open</button>
    
    <!-- This is an anchor toggling the modal -->
    <a href="#modal-example" uk-toggle>Open</a>
    
    <!-- This is the modal -->
    <div id="modal-example" uk-modal>
        <div class="uk-modal-dialog uk-modal-body">
            <h2 class="uk-modal-title">Headline</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>
        </div>
    </div>

关闭按钮

要创建一个关闭按钮,启用其功能并添加适当的样式和定位,请向 <a><button> 元素添加 .uk-modal-close-default 类。要将关闭按钮放置在模态框外部,请添加 .uk-modal-close-outside 类。

关闭组件 中添加 uk-close 属性,以应用关闭图标。

<div>
    <div class="uk-modal-dialog">
        <button class="uk-modal-close-default" type="button" uk-close></button>
    </div>
</div>

<div>
    <div class="uk-modal-dialog">
        <button class="uk-modal-close-outside" type="button" uk-close></button>
    </div>
</div>
  • <!-- This is a button toggling the modal with the default close button -->
    <button class="uk-button uk-button-default uk-margin-small-right" type="button" uk-toggle="target: #modal-close-default">Default</button>
    
    <!-- This is the modal with the default close button -->
    <div id="modal-close-default" uk-modal>
        <div class="uk-modal-dialog uk-modal-body">
            <button class="uk-modal-close-default" type="button" uk-close></button>
            <h2 class="uk-modal-title">Default</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>
    
    <!-- This is a button toggling the modal with the outside close button -->
    <button class="uk-button uk-button-default uk-margin-small-right" type="button" uk-toggle="target: #modal-close-outside">Outside</button>
    
    <!-- This is the modal with the outside close button -->
    <div id="modal-close-outside" uk-modal>
        <div class="uk-modal-dialog uk-modal-body">
            <button class="uk-modal-close-outside" type="button" uk-close></button>
            <h2 class="uk-modal-title">Outside</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>

居中模态框

要垂直居中模态框对话框,您可以使用 边距组件 中的 .uk-margin-auto-vertical 类。

<div class="uk-flex-top" uk-modal>
    <div class="uk-modal-dialog uk-margin-auto-vertical"></div>
</div>
  • 打开
  • <a class="uk-button uk-button-default" href="#modal-center" uk-toggle>Open</a>
    
    <div id="modal-center" class="uk-flex-top" uk-modal>
        <div class="uk-modal-dialog uk-modal-body uk-margin-auto-vertical">
    
            <button class="uk-modal-close-default" type="button" uk-close></button>
    
            <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>

注意 模态框容器上的 .uk-flex-top 是支持 IE 11 所必需的。


要将模态框划分为不同的内容部分,请使用以下类。

描述
.uk-modal-header 将此类添加到 <div> 元素以创建模态框页眉。
.uk-modal-footer 将此类添加到 <div> 元素以创建模态框页脚。
<div uk-modal>
    <div class="uk-modal-dialog">
        <button class="uk-modal-close-default" type="button" uk-close></button>
        <div class="uk-modal-header">
            <h2 class="uk-modal-title"></h2>
        </div>
        <div class="uk-modal-body"></div>
        <div class="uk-modal-footer"></div>
    </div>
</div>
  • 打开
  • <a class="uk-button uk-button-default" href="#modal-sections" uk-toggle>Open</a>
    
    <div id="modal-sections" uk-modal>
        <div class="uk-modal-dialog">
            <button class="uk-modal-close-default" type="button" uk-close></button>
            <div class="uk-modal-header">
                <h2 class="uk-modal-title">Modal Title</h2>
            </div>
            <div class="uk-modal-body">
                <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 class="uk-modal-footer 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>
            </div>
        </div>
    </div>

容器修饰符

添加 .uk-modal-container 类以将模态框对话框扩展到默认的 容器 宽度。

<div class="uk-modal-container" uk-modal>…</div>
  • 打开
  • <a class="uk-button uk-button-default" href="#modal-container" uk-toggle>Open</a>
    
    <div id="modal-container" class="uk-modal-container" uk-modal>
        <div class="uk-modal-dialog uk-modal-body">
            <button class="uk-modal-close-default" type="button" uk-close></button>
            <h2 class="uk-modal-title">Headline</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>

完整修饰符

要创建一个填充整个页面的模态框,请添加 .uk-modal-full 类。建议还将 .uk-modal-close-full 类添加到关闭按钮,以便它调整其样式。

<div class="uk-modal-full" uk-modal>
    <div class="uk-modal-dialog">
        <button class="uk-modal-close-full uk-close-large" type="button" uk-close></button>
    </div>
</div>

使用 网格宽度 类,您可以创建一个漂亮的分割全屏模态框。

  • 打开
  • <a class="uk-button uk-button-default" href="#modal-full" uk-toggle>Open</a>
    
    <div id="modal-full" class="uk-modal-full" uk-modal>
        <div class="uk-modal-dialog">
            <button class="uk-modal-close-full uk-close-large" type="button" uk-close></button>
            <div class="uk-grid-collapse uk-child-width-1-2@s uk-flex-middle" uk-grid>
                <div class="uk-background-cover" style="background-image: url('images/photo.jpg');" uk-height-viewport></div>
                <div class="uk-padding-large">
                    <h1>Headline</h1>
                    <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>
        </div>
    </div>

溢出

默认情况下,如果模态框的内容超过窗口高度,页面将与模态框一起滚动。要在模态框内部应用滚动条,请向模态框主体添加来自 工具组件uk-overflow-auto 属性。

<div uk-modal>
    <div class="uk-modal-dialog" uk-overflow-auto></div>
</div>
  • 打开
  • <a class="uk-button uk-button-default" href="#modal-overflow" uk-toggle>Open</a>
    
    <div id="modal-overflow" uk-modal>
        <div class="uk-modal-dialog">
    
            <button class="uk-modal-close-default" type="button" uk-close></button>
    
            <div class="uk-modal-header">
                <h2 class="uk-modal-title">Headline</h2>
            </div>
    
            <div class="uk-modal-body" uk-overflow-auto>
    
                <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>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>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>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>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>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>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>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>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 class="uk-modal-footer 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>
            </div>
    
        </div>
    </div>

媒体

如果您想显示媒体,您应该首先检查 灯箱组件 是否已经提供您需要的所有功能。但是,您也可以使用模态框来更多地控制将媒体包装在其中的标记。

注意 使用来自 视频组件uk-video 属性,确保视频在模态框关闭时停止。

<div uk-modal>
    <div class="uk-modal-dialog uk-width-auto">
        <iframe src="" uk-video></iframe>
    </div>
</div>
  • 图片 视频 YouTube Vimeo

  •  <p uk-margin>
        <a class="uk-button uk-button-default" href="#modal-media-image" uk-toggle>Image</a>
        <a class="uk-button uk-button-default" href="#modal-media-video" uk-toggle>Video</a>
        <a class="uk-button uk-button-default" href="#modal-media-youtube" uk-toggle>YouTube</a>
        <a class="uk-button uk-button-default" href="#modal-media-vimeo" uk-toggle>Vimeo</a>
    </p>
    
    <div id="modal-media-image" class="uk-flex-top" uk-modal>
        <div class="uk-modal-dialog uk-width-auto uk-margin-auto-vertical">
            <button class="uk-modal-close-outside" type="button" uk-close></button>
            <img src="images/photo.jpg" width="1800" height="1200" alt="">
        </div>
    </div>
    
    <div id="modal-media-video" class="uk-flex-top" uk-modal>
        <div class="uk-modal-dialog uk-width-auto uk-margin-auto-vertical">
            <button class="uk-modal-close-outside" type="button" uk-close></button>
            <video src="https://yootheme.com/site/images/media/yootheme-pro.mp4" width="1920" height="1080" controls playsinline uk-video></video>
        </div>
    </div>
    
    <div id="modal-media-youtube" class="uk-flex-top" uk-modal>
        <div class="uk-modal-dialog uk-width-auto uk-margin-auto-vertical">
            <button class="uk-modal-close-outside" type="button" uk-close></button>
            <iframe src="https://www.youtube-nocookie.com/embed/c2pz2mlSfXA" width="1920" height="1080" loading="lazy" uk-video uk-responsive></iframe>
        </div>
    </div>
    
    <div id="modal-media-vimeo" class="uk-flex-top" uk-modal>
        <div class="uk-modal-dialog uk-width-auto uk-margin-auto-vertical">
            <button class="uk-modal-close-outside" type="button" uk-close></button>
            <iframe src="https://player.vimeo.com/video/1084537" width="1280" height="720" loading="lazy" uk-video uk-responsive></iframe>
        </div>
    </div>

您可以通过从一个模态框链接到另一个模态框并返回来对多个模态框进行分组。使用此方法在模态框中创建多步骤向导。

<div id="modal-group-1" uk-modal>
    <div class="uk-modal-dialog">
        <a href="#modal-group-2" uk-toggle>Next</a>
    </div>
</div>

<div id="modal-group-2" uk-modal>
    <div class="uk-modal-dialog">
        <a href="#modal-group-1" uk-toggle>Previous</a>
    </div>
</div>
  • 模态框 1 模态框 2

  • <p uk-margin>
        <a class="uk-button uk-button-default" href="#modal-group-1" uk-toggle>Modal 1</a>
        <a class="uk-button uk-button-default" href="#modal-group-2" uk-toggle>Modal 2</a>
    </p>
    
    <div id="modal-group-1" uk-modal>
        <div class="uk-modal-dialog">
            <button class="uk-modal-close-default" type="button" uk-close></button>
            <div class="uk-modal-header">
                <h2 class="uk-modal-title">Headline 1</h2>
            </div>
            <div class="uk-modal-body">
                <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 class="uk-modal-footer uk-text-right">
                <button class="uk-button uk-button-default uk-modal-close" type="button">Cancel</button>
                <a href="#modal-group-2" class="uk-button uk-button-primary" uk-toggle>Next</a>
            </div>
        </div>
    </div>
    
    <div id="modal-group-2" uk-modal>
        <div class="uk-modal-dialog">
            <button class="uk-modal-close-default" type="button" uk-close></button>
            <div class="uk-modal-header">
                <h2 class="uk-modal-title">Headline 2</h2>
            </div>
            <div class="uk-modal-body">
                <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 class="uk-modal-footer uk-text-right">
                <button class="uk-button uk-button-default uk-modal-close" type="button">Cancel</button>
                <a href="#modal-group-1" class="uk-button uk-button-primary" uk-toggle>Previous</a>
            </div>
        </div>
    </div>

组件选项

任何这些选项都可以应用于组件属性。用分号分隔多个选项。 了解更多

选项 默认 描述
esc-close 布尔值 true 按下 Esc 键时关闭模态框。
bg-close 布尔值 true 单击背景时关闭模态框。
stack 布尔值 false 堆叠模态框,当多个模态框处于打开状态时。默认情况下,上一个模态框将被隐藏。
container 字符串 true 通过选择器定义一个目标容器以指定模态框在 DOM 中应附加的位置。将其设置为 false 将阻止此行为。
cls-page 字符串 uk-modal-page 在模态框处于活动状态时添加到 <html> 的类
cls-panel 字符串 uk-modal-dialog 将被视为模态框面板的元素的类
sel-close 字符串 .uk-modal-close, .uk-modal-close-default, .uk-modal-close-outside, .uk-modal-close-full 应触发模态框关闭的所有元素的 CSS 选择器

JavaScript

了解更多关于 JavaScript 组件

初始化

UIkit.modal(element, options);

事件

以下事件将在附加了此组件的元素上触发

名称 描述
beforeshow 在显示项目之前触发。
show 在显示项目后触发。
shown 在项目的显示动画完成之后触发。
beforehide 在隐藏项目之前触发。
hide 在项目的隐藏动画开始后触发。
hidden 在隐藏项目后触发。

方法

以下方法可用于组件

显示

UIkit.modal(element).show();

显示模态框。

隐藏

UIkit.modal(element).hide();

隐藏模态框。


组件附带了许多您可以用于用户交互的预制模态对话框。您可以直接从 JavaScript 调用对话框,并使用回调函数来处理用户输入。

代码 描述
UIkit.modal.alert('UIkit 警报!') 显示一个带有一个按钮的警报框。
UIkit.modal.confirm('UIkit 确认!') 显示一个带您消息和两个按钮的确认对话框。
UIkit.modal.prompt('姓名:', '您的姓名') 显示一个询问文本输入的对话框。
UIkit.modal.dialog('<p>UIkit 对话框!</p>'); 显示包含任何 HTML 内容的对话框。

要处理用户输入,模态框使用基于 Promise 的接口,该接口提供 then() 函数来注册您的回调函数。但是,UIkit.modal.dialog 函数将返回模态框本身。

UIkit.modal.confirm('UIkit confirm!').then(function() {
    console.log('Confirmed.')
}, function () {
    console.log('Rejected.')
});

返回的 Promise 具有一个属性 dialog,它保存对模态框本身的引用。这使您可以操作模态框元素的标记等。

要翻译按钮标签,对话框函数接受一个可选的 options 对象参数。它有一个键 i18n 和两个属性 okcancel

const modal = UIkit.modal.confirm('UIkit confirm!', {i18n: {ok: 'okay'}}).dialog; // The modal component
const el = modal.$el; // The modal element
  • 对话框 警报 确认 提示

  • <p uk-margin>
    
        <a id="js-modal-dialog" class="uk-button uk-button-default" href="#">Dialog</a>
    
        <a id="js-modal-alert" class="uk-button uk-button-default" href="#">Alert</a>
    
        <a id="js-modal-confirm" class="uk-button uk-button-default" href="#">Confirm</a>
    
        <a id="js-modal-prompt" class="uk-button uk-button-default" href="#">Prompt</a>
    
        <script>
    
           UIkit.util.on('#js-modal-dialog', 'click', function (e) {
               e.preventDefault();
               e.target.blur();
               UIkit.modal.dialog('<p class="uk-modal-body">UIkit dialog!</p>');
           });
    
           UIkit.util.on('#js-modal-alert', 'click', function (e) {
               e.preventDefault();
               e.target.blur();
               UIkit.modal.alert('UIkit alert!').then(function () {
                   console.log('Alert closed.')
               });
           });
    
           UIkit.util.on('#js-modal-confirm', 'click', function (e) {
               e.preventDefault();
               e.target.blur();
               UIkit.modal.confirm('UIkit confirm!').then(function () {
                   console.log('Confirmed.')
               }, function () {
                   console.log('Rejected.')
               });
           });
    
           UIkit.util.on('#js-modal-prompt', 'click', function (e) {
               e.preventDefault();
               e.target.blur();
               UIkit.modal.prompt('Name:', 'Your name').then(function (name) {
                   console.log('Prompted:', name)
               });
           });
    
        </script>
    
    </p>

无障碍

模态框组件遵循 对话框 (模态框) WAI-ARIA 设计模式 并自动设置适当的 WAI-ARIA 角色和属性。

关闭组件自动设置适当的 WAI-ARIA 角色和属性。

键盘交互

可以使用以下键通过键盘访问模态框组件。