jQuery Mobile - 導航欄基礎



說明

可以使用 data-role = "navbar" 屬性建立導航欄。當導航欄按鈕被單擊時,它獲得活動狀態。ui-btn-active 類將從所有導航欄錨中刪除,並新增到已啟用的連結中。

如果這是到其他頁面的連結,則在過渡完成類之後再次刪除。根據導航欄專案,瀏覽器的寬度將在專案之間均勻分配。

示例

以下示例演示了在 jQuery Mobile 中使用 基本導航欄

<!DOCTYPE html>
<html>
   <head>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
   </head>
   
   <body>
      <p>Navbar will be rendered 100% with one item.</p>
      <div data-role = "navbar">
         <ul>
            <li><a href = "#" class = "ui-btn-active">One</a></li>
         </ul>
      </div>
      
      <p>Navbar will be rendered 50% with two items.</p>
      <div data-role = "navbar">
         <ul>
            <li><a href = "#" class = "ui-btn-active">One</a></li>
            <li><a href = "#">Two</a></li>
         </ul>
      </div>
      
      <p>Each button will take 1/3 width of the browser window when navbar has 3 items.</p>
      <div data-role = "navbar">
         <ul>
            <li><a href = "#" class = "ui-btn-active">One</a></li>
            <li><a href = "#">Two</a></li>
            <li><a href = "#">Three</a></li>
         </ul>
      </div>
      
      <p>Each button will take 1/4 width of the browser window when navbar has 4 items.</p>
      <div data-role = "navbar">
         <ul>
            <li><a href = "#" class = "ui-btn-active">One</a></li>
            <li><a href = "#">Two</a></li>
            <li><a href = "#">Three</a></li>
            <li><a href = "#">Four</a></li>
         </ul>
      </div>
      
      <p>Each button will take 1/5 width of the browser window when navbar has 5 items.</p>
      <div data-role = "navbar">
         <ul>
            <li><a href = "#" class = "ui-btn-active">One</a></li>
            <li><a href = "#">Two</a></li>
            <li><a href = "#">Three</a></li>
            <li><a href = "#">Four</a></li>
            <li><a href = "#">Five</a></li>
         </ul>
      </div>
   </body>
</html>

輸出

讓我們執行以下步驟,瞭解上述程式碼如何工作 -

  • 將上述 html 程式碼另存為 navbar_basic.html 檔案,儲存在伺服器根資料夾中。

  • 開啟此 HTML 檔案,網址為 https:///navbar_basic.html,將顯示以下輸出。

jquery_mobile_widgets.htm
廣告
© . All rights reserved.