使用JavaScript(Using JavaScript)

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

描述 (Description)

可以使用相关的app方法使用JavaScript openedclosed面板,如下所示 -

  • myApp.openPanel(position) - 用于打开接受面板位置(左或右)作为字符串的面板。

  • myApp.closePanel() - 它关闭当前打开的面板。 单击“ Open Left Panel并显示右侧面板时,该示例显示左侧面板,单击“ Open Right Panel

例子 (Example)

以下示例演示了在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>Open and Close Panels</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">
            <p>Left Panel content</p>
            <p><a href = "#" class = "open-right-panel">Open Right Panel</a></p>
            <p><a href = "#" class = "panel-close">Close me</a></p>
         </div>
      </div>
      <div class = "panel panel-right panel-cover">
         <div class = "content-block">
            <p>Right Panel content</p>
            <p><a href = "#" class = "open-left-panel">Open Left Panel</a></p>
            <p><a href = "#" class = "panel-close">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">Open Panels with JavaScript</div>
                        <div class = "right"> </div>
                     </div>
                  </div>
                  <div class = "page-content">
                     <div class = "content-block">
                        <p> <a href = "#" class = "open-left-panel">Open Left Panel</a></p>
                        <p> <a href = "#" class = "open-right-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;
         $$('.open-left-panel').on('click', function (e) {
            // 'left' position to open Left panel
            myApp.openPanel('left');
         });
         $$('.open-right-panel').on('click', function (e) {
            // 'right' position to open Right panel
            myApp.openPanel('right');
         });
         $$('.panel-close').on('click', function (e) {
            myApp.closePanel();
         });
      </script>
   </body>
</html>

输出 (Output)

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

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

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

  • 单击“ Open Left Panel链接时,此示例显示左侧面板,单击“ Open Right Panel链接时显示右侧面板。