Framework7 - 面板事件

描述

要检测用户如何与面板交互,您可以使用面板事件。它还可用于在面板打开/关闭时在 JS 中执行某些操作。

下表列出了 Framework7 支持的事件 −

S.No Event &描述 目标
1

open

每当面板开始其打开动画时,都会触发此事件。

面板元素

<div class = "panel">

2

opened

每当面板完成其打开动画时,都会触发此事件。

面板元素

<div class = "panel">

3

close

每当启动面板关闭动画时,都会触发此事件。

面板元素

<div class = "panel">

4

closed

每当面板关闭动画完成时,都会触发此事件。

面板元素

<div class = "panel">

示例

以下示例演示了 Framework7 中的面板事件。该示例检测用户与面板的交互并相应地显示事件消息。

<!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>Panel Events</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 = "panel-overlay"></div>
      
      <div class = "panel panel-left panel-reveal">
         <div class = "content-block">
            <h2>Left Panel content</h2>
            <p><a href = "#" data-panel = "right" class = "open-panel">Open Right Panel</a></p>
            <p><a href = "#" class = "close-panel">Close me</a></p>
         </div>
      </div>
      
      <div class = "panel panel-right panel-cover">
         <div class = "content-block">
            <h2>Right Panel content</h2>
            <p><a href = "#" data-panel = "left" class = "open-panel">Open Left Panel</a></p>
            <p><a href = "#" class = "close-panel">Close me</a></p>
         </div>
      </div>
      
      <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"> </div>
                        <div class = "center">Side Panel Events</div>
                        <div class = "right"> </div>
                     </div>
                  </div>
                  
                  <div class = "page-content">
                     <div class = "content-block">
                        <p> <a href = "#" class = "open-panel">Open Left Panel</a></p>
                        <p> <a href = "#" data-panel = "right" class = "open-panel">Open Right Panel</a></p>
                     </div>
                  </div>
               
               </div>
            </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;

         $$('.panel-left').on('opened', function () {
            myApp.alert('Left panel opened!!');
         });
         
         $$('.panel-left').on('close', function () {
            myApp.alert('Left panel is closing!!');
         });
         
         $$('.panel-right').on('open', function () {
            myApp.alert('Right panel is opening!!');
         });
         
         $$('.panel-right').on('closed', function () {
            myApp.alert('Right panel closed!!');
         });
      </script>
   </body>

</html>

输出

让我们执行以下步骤来查看上述代码的工作原理 −

  • 将上述 HTML 代码保存为服务器根文件夹中的 sidepanels_events.html 文件。

  • 将此 HTML 文件作为 http://localhost/sidepanels_events.html 打开,输出如下所示。

  • 此示例在单击 打开左面板链接时显示左面板,在单击 打开右面板链接时显示右面板,并且面板状态打开和关闭动画时将触发面板事件。

framework7_side_panels.html