Bulma教程

Bulma Modal

说明

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.lidihuo.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.lidihuo.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>
它显示以下输出-
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4