From HTML

优质
小牛编辑
130浏览
2023-12-01

描述 (Description)

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

  • 要打开popover,请将open-popover类添加到任何HTML元素,并且可以使用add close-popover类来关闭popover。

  • 当你在app中有很多popover时,你需要将data-popover=".mypopover"属性指定给适当的data-popover=".mypopover"

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

例子 (Example)

以下示例演示了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>

输出 (Output)

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

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

  • 以http://localhost/popover_open_close_html.html打开此HTML文件,输出显示如下。

  • 单击第一个链接时,将打开about popover窗口。 同样,当您单击第二个链接时,将打开包含多个菜单项的菜单弹出窗口。

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

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