Framework7 - 狀態列



描述

iOS 7+ 允許您構建全屏應用程式,這在狀態列與您的應用程式重疊時可能會造成問題。Framework7 透過檢測您的應用程式是否處於全屏模式來解決此問題。如果您的應用程式處於全屏模式,則 Framework7 會自動將 with-statusbar-overlay 類新增到 <html>(或在應用程式不處於全屏模式時將其移除),並且您需要在 <body> 中新增 statusbar-overlay 類,如下面的程式碼所示:

<html class = "with-statusbar-overlay">
...
   <body>
      <div class = "statusbar-overlay"></div>
      ...

預設情況下,<div> 將始終隱藏並固定在螢幕頂部。它僅在應用程式處於全屏模式且 with-statusbar-overlay 類新增到 <html> 時可見。

示例

以下示例演示了在 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>My App</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 = "statusbar-overlay"></div>
      <div class = "panel-overlay"></div>
      
      <div class = "panel panel-right panel-reveal">
         <div class = "content-block">
            <p>Contents goes here...</p>
         </div>
      </div>
      
      <div class = "views">
         <div class = "view view-main">
            <div class = "navbar">
               <div class = "navbar-inner">
                  <div class = "center sliding">My App</div>
                  
                  <div class = "right">
                     <a href = "#" class = "link icon-only open-panel"><i class = "icon icon-bars"></i></a>
                  </div>
                  
               </div>
            </div>
            
            <div class = "pages navbar-through toolbar-through">
               <div data-page = "index" class = "page">
                  <div class = "page-content">
                     <p>This is simple application...</p>
                     <p>page contents goes here!!!</p>
                  </div>
               </div>
            </div>
            
            <div class = "toolbar">
               <div class = "toolbar-inner">
                  <a href = "#" class = "link">First Link</a>
                  <a href = "#" class = "link">Second Link</a>
               </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>
         // here initialize the app
         var myApp = new Framework7();

         // If your using custom DOM library, then save it to $$ variable
         var $$ = Dom7;

         // Add the view
         var mainView = myApp.addView('.view-main', {
            // enable the dynamic navbar for this view:
            dynamicNavbar: true
         });

         //use the 'pageInit' event handler for all pages
         $$(document).on('pageInit', function (e) {
            //get page data from event data
            var page = e.detail.page;
         })
      </script>
   </body>

</html>

輸出

讓我們執行以下步驟來檢視上面給出的程式碼是如何工作的:

  • 將上面給出的 html 程式碼儲存為 status_bar.html 檔案到您的伺服器根目錄。

  • 以 https:///status_bar.html 的方式開啟此 HTML 檔案,輸出將如下所示。

此示例展示了 statusbar-overlay 的用法,它允許您在狀態列與應用程式重疊時構建全屏應用程式。

廣告