Framework7 - 从 HTML 打开和关闭弹出窗口



描述

所需的弹出窗口可以使用链接上的特殊类和数据属性来打开和关闭。以下语句简要描述了如何打开/关闭弹出窗口 -

  • 要打开弹出窗口,请向任何 HTML 元素添加 open-popover 类,并且可以使用 close-popover 类关闭弹出窗口。

  • 当您在应用程序中有多个弹出窗口时,需要将 data-popover=".mypopover" 属性指定到相应的弹出窗口。

  • 当使用此方法(从 HTML)打开弹出窗口时,弹出窗口将自动放置在我们点击以调用此弹出窗口的元素周围。

示例

以下示例演示了在 Framework7 中从 HTML 打开和关闭弹出窗口 -

<!DOCTYPE html>
<html>

   <head>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, 
         maximum-scale = 1, minimum-scale = 1, user-scalable = no, minimal-ui" />
      <meta name = "apple-mobile-web-app-capable" content = "yes" />
      <meta name = "apple-mobile-web-app-status-bar-style" content = "black" />
      <title>Open and close Popover From HTML</title>
      <link rel = "stylesheet" 
         href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.min.css" />
      <link rel = "stylesheet" 
         href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.colors.min.css" />
   </head>

   <body>
      <div class = "views">
         <div class = "view view-main">
            <div class = "pages">
               <div data-page = "home" class = "page navbar-fixed">
               
                  <div class = "navbar">
                     <div class = "navbar-inner">
                        <div class = "left"> <a href = "#" data-popover = ".popover-menus" class = "link open-popover">Menus</a></div>
                        <div class = "center">Open and close Popover From HTML</div>
                        <div class = "right"> <a href = "#" data-popover = ".popover-about" class = "link open-popover">About</a></div>
                     </div>
                  </div>
                  
                  <div class = "page-content">
                     <div class = "content-block">
                        <p><a href = "#" data-popover = ".popover-about" class = "open-popover">Open About Popover</a></p>
                        <p><a href = "#" data-popover = ".popover-menus" class = "open-popover">Open Menus Popover</a></p>
                     </div>
                  </div>
                  
               </div>
            </div>
         </div>
      </div>
      
      <style>.popover{width:200px;}</style>
      <div class = "popover popover-about">
         <div class = "popover-angle"></div>
         
         <div class = "popover-inner">
            <div class = "content-block">
               <p>About</p>
               <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ac 
               diam ac quam euismod porta vel a nunc.</p>
            </div>
         </div>
      </div>
      
      <div class = "popover popover-menus">
         <div class = "popover-angle"></div>
         <div class = "popover-inner">
            <div class = "list-block">
               <ul>
                  <li><a href = "#" class = "list-button item-link">Menu 1</a></li>
                  <li><a href = "#" class = "list-button item-link">Menu 2</a></li>
                  <li><a href = "#" class = "list-button item-link">Menu 3</a></li>
                  <li><a href = "#" class = "list-button item-link">Menu 4</a></li>
                  <li><a href = "#" class = "list-button item-link">Menu 5</a></li>
               </ul>
            </div>
         </div>
      </div>
      
      <script type = "text/javascript" 
         src = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/js/framework7.min.js"></script>
         
      <script>
         var myApp = new Framework7();
         var $$ = Dom7;
      </script>
   </body>

</html>

输出

让我们执行以下步骤来了解上面给出的代码是如何工作的 -

  • 将上面给出的 HTML 代码保存为 popover_open_close_html.html 文件,放在您的服务器根目录文件夹中。

  • 以 https://127.0.0.1/popover_open_close_html.html 的方式打开此 HTML 文件,输出结果如下所示。

  • 当您点击第一个链接时,将打开关于弹出窗口。类似地,当您点击第二个链接时,将打开具有多个菜单项的菜单弹出窗口。

  • 菜单和关于弹出窗口也可以通过点击顶部的菜单和关于选项来打开。弹出窗口将从 HTML 中打开和关闭。

当您点击链接时,弹出窗口将使用 popover 类打开,如果您点击鼠标外部,弹出窗口将关闭。

framework7_overlays.htm
广告