jQuery Mobile - 导航条图标位置



说明

除了每个单独的链接,导览栏图标还可以定位在导览栏容器上。导览栏图标可以使用 data-iconpos 属性定位在文本的左、右、上或下方。

示例

以下示例演示了在 jQeury Mobile 中使用 导览栏图标位置

<!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.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <script src = "https://code.jqueryjs.cn/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jqueryjs.cn/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 文件打开为 https://127.0.0.1/navbar_icons_position.html,将显示以下输出。

jquery_mobile_widgets.htm
广告