jQuery Mobile - 彈出位置



說明

你可以透過以下三種方式指定彈出框位置:

  • data-position-to = "window" - 彈出框將定位到視窗。

  • data-position-to = "origin" - 彈出框將定位在原點上方。

  • data-position-to = "#specified_position_id" - 彈出框將定位在具有指定 #id 的元素上方。

範例

以下示例演示了在 jQuery Mobile 框架中使用彈出框位置

<!DOCTYPE html>
<html>
   <head>
      <title>Popup 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>
      <div data-role = "page">
         <div data-role = "header">
            <h2>Header</h2>
         </div>
         
         <div id = "page1" data-role = "main" class = "ui-content">
            <a href = "#position_window" class = "ui-btn ui-btn-inline" data-rel = "popup" 
               data-position-to = "window">Window  Position</a>
               
            <a href = "#position_origin" class = "ui-btn ui-btn-inline" data-rel = "popup" 
               data-position-to = "origin">Origin Position</a>
               
            <a href = "#position_selector" class = "ui-btn ui-btn-inline" 
               data-rel = "popup" data-position-to = "#myheader">Position to Spefied Id</a>
               
            <div data-role = "popup" id = "position_window" class = "ui-content" 
               data-theme = "a">
               <p>This is positioned to the window.</p>
            </div>
            
            <div data-role = "popup" id = "position_origin" class = "ui-content" 
               data-theme = "a">
               <p>This is positioned to the origin.</p>
            </div>
            
            <div data-role = "popup" id = "position_selector" class = "ui-content" 
               data-theme = "a">
               <p>This is positioned to specified Id. Popup is positioned over the element 
               with a specified #id.</p>
            </div>
         </div>
         
         <div data-role = "footer">
            <h2>Footer</h2>
         </div>
      </div>
   </body>
</html>

輸出

讓我們執行以下步驟,看看上面的程式碼如何工作:

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

  • 以 https:///jqm_popup_position.html 的形式開啟此 HTML 檔案,將會顯示以下輸出。

jquery_mobile_widgets.htm
廣告
© . All rights reserved.