jQuery Mobile - 导航栏图标位置

描述

导航栏图标可以放置在导航栏容器上,而不是每个链接上。 导航栏图标可以使用 data-iconpos 属性定位在文本的左侧、右侧、顶部或底部。


示例

以下示例演示了在 jQuery Mobile 中使用 navbar icons position

<!DOCTYPE html>
<html>
   <head>
      <title>Navbar Icons Position</title>
      <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>Icons placed at bottom:</p>
      <div data-role = "navbar" data-iconpos = "bottom">
         <ul>
            <li><a href = "#" data-icon = "mail">Messages</a></li>
            <li><a href = "#" data-icon = "user" class = "ui-btn-active">Friends</a></li>
            <li><a href = "#" data-icon = "star">Notifications</a></li>
         </ul>
      </div>
      
      <p>Icons placed at top:</p>
      <div data-role = "navbar" data-iconpos = "top">
         <ul>
            <li><a href = "#" data-icon = "mail">Messages</a></li>
            <li><a href = "#" data-icon = "user" class = "ui-btn-active">Friends</a></li>
            <li><a href = "#" data-icon = "star">Notifications</a></li>
         </ul>
      </div>
      
      <p>Icons placed at left:</p>
      <div data-role = "navbar" data-iconpos = "left">
         <ul>
            <li><a href = "#" data-icon = "mail">Messages</a></li>
            <li><a href = "#" data-icon = "user" class = "ui-btn-active">Friends</a></li>
            <li><a href = "#" data-icon = "star">Notifications</a></li>
         </ul>
      </div>
      
      <p>Icons placed at right:</p>
      <div data-role = "navbar" data-iconpos = "right">
         <ul>
            <li><a href = "#" data-icon = "mail">Messages</a></li>
            <li><a href = "#" data-icon = "user" class = "ui-btn-active">Friends</a></li>
            <li><a href = "#" data-icon = "star">Notifications</a></li>
         </ul>
      </div>
   </body>
</html>

输出

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

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

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

❮ jQuery Mobile - 小部件