Bulma - 模态
描述
Modal 是覆盖在父窗口上的子窗口。它显示来自单独源的内容,无需离开父窗口即可进行一些交互。
您可以使用 modal 类以及以下 3 个模态类显示模态 −
modal-background − 它显示透明覆盖层。
modal-content − 它将模态内容包含在水平和垂直居中的容器中。
modal-close − 它用于关闭模态窗口。
以下示例显示了在页面中使用上述类显示模态 −
<!DOCTYPE html> <html> <head> <meta charset = "utf-8"> <meta name = "viewport" content = "width = device-width, initial-scale = 1"> <title>Bulma Elements Example</title> <link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css"> <script src = "https://use.fontawesome.com/releases/v5.1.0/js/all.js"></script> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <section class = "section"> <div class = "container"> <span class = "title"> Simple Modal </span> <br> <br> <p> <a class = "button is-primary modal-button" data-target = "#modal">Launch example modal</a> </p> <div id = "modal" class = "modal"> <div class = "modal-background"></div> <div class = "modal-content"> <div class = "box"> <article class = "media"> <div class = "media-left"> <figure class = "image is-64x64"> <img src = "https://www.tutorialspoint.com/bootstrap/images/64.jpg" alt="Image"> </figure> </div> <div class = "media-content"> <div class = "content"> <p> <strong>Will Smith</strong> <small>@wsmith</small> <small>31m</small> <br> This is simple text. This is simple text. This is simple text. This is simple text. </p> </div> <nav class = "level"> <div class = "level-left"> <a class = "level-item"> <span class = "icon is-small"> <i class = "fa fa-reply"></i> </span> </a> <a class = "level-item"> <span class = "icon is-small"> <i class = "fa fa-retweet"></i> </span> </a> </div> </nav> </div> </article> </div> </div> <button class = "modal-close is-large" aria-label = "close"></button> </div> </div> </section> <script> $(".modal-button").click(function() { var target = $(this).data("target"); $("html").addClass("is-clipped"); $(target).addClass("is-active"); }); $(".modal-close").click(function() { $("html").removeClass("is-clipped"); $(this).parent().removeClass("is-active"); }); </script> </body> </html>
它显示以下输出 −
图像模式
Bulma 允许您通过添加 image 类以及图像路径在模式中显示图像,如下例所示 −
<!DOCTYPE html> <html> <head> <meta charset = "utf-8"> <meta name = "viewport" content = "width = device-width, initial-scale = 1"> <title>Bulma Elements Example</title> <link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css"> <script src = "https://use.fontawesome.com/releases/v5.1.0/js/all.js"></script> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <section class = "section"> <div class = "container"> <span class = "title"> Image Modal </span> <br> <br> <p> <a class = "button is-primary modal-button" data-target = "#modal">Launch image modal</a> </p> <div id = "modal" class = "modal"> <div class = "modal-background"></div> <div class = "modal-content"> <p class = "image is-128x128"> <img src = "https://www.tutorialspoint.com/bootstrap/images/64.jpg" alt=""> </p> </div> <button class = "modal-close is-large" aria-label="close"></button> </div> </div> </section> <script> $(".modal-button").click(function() { var target = $(this).data("target"); $("html").addClass("is-clipped"); $(target).addClass("is-active"); }); $(".modal-close").click(function() { $("html").removeClass("is-clipped"); $(this).parent().removeClass("is-active"); }); </script> </body> </html>
它显示以下输出 −
模态卡
Bulma 使用模态卡在框中显示内容,以获得更好的外观。
让我们使用 modal-card 类为模态卡创建一个示例 −
<!DOCTYPE html> <html> <head> <meta charset = "utf-8"> <meta name = "viewport" content = "width = device-width, initial-scale = 1"> <title>Bulma Elements Example</title> <link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css"> <script src = "https://use.fontawesome.com/releases/v5.1.0/js/all.js"></script> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <section class = "section"> <div class = "container"> <span class = "title"> Modal Card </span> <br> <br> <p> <a class = "button is-primary modal-button" data-target = "#modal">Launch Card modal</a> </p> <div id = "modal" class = "modal"> <div class = "modal-background"></div> <div class = "modal-card"> <header class = "modal-card-head"> <p class = "modal-card-title">Modal Card</p> <button class = "delete" aria-label = "close"></button> </header> <section class = "modal-card-body"> <div class = "content"> <h1>Level One</h1> <p> This is simple text. This is simple text. This is simple text. This is simple text. </p> <h2>Level Two</h2> <p> This is simple text. This is simple text. This is simple text. This is simple text. </p> <h3>Level Three</h3> <blockquote> This is simple text. This is simple text. This is simple text. This is simple text. </blockquote> <h4>Level Four</h4> <p> This is simple text. This is simple text. This is simple text. This is simple text. </p> <h5>Level Five</h5> <p> This is simple text. This is simple text. This is simple text. This is simple text. </p> </ul> </div> </section> </div> </div> </div> </section> <script> $(".modal-button").click(function() { var target = $(this).data("target"); $("html").addClass("is-clipped"); $(target).addClass("is-active"); }); $(".modal-close").click(function() { $("html").removeClass("is-clipped"); $(this).parent().removeClass("is-active"); }); </script> </body> </html>
它显示以下输出 −