jQuery Mobile - 弹出窗口对齐

描述

为页面中的弹出窗口设置沿 x 轴或 y 轴的对齐方式。


示例

以下示例演示了在 jQuery Mobile 框架中使用弹出窗口对齐

<!DOCTYPE html>
<html>
   <head>
      <title>Popup Alignment</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>
      <script src = "http://demos.jquerymobile.com/1.4.5/popup-alignment/popup.alignment.js"></script>
      
      <script>
         ( function( $, undefined ) {
            $.mobile.document.on( "slidestop", function() {
               setTimeout( function() {
                  $( "#alignment_popup" ).popup( "option", "align",
                  $( "#x-axis" ).val() + "," + $( "#y-axis" ).val() );
               }, 300 );
            });
         })( jQuery );
      </script>
      
      <style>
         #alignment_popup {
            min-width: 200px;
            opacity: 0.8;
         }
         
         #alignment_popup1 {
            position: relative;
            left: 50%;
         }
      </style>
   </head>
   
   <body>
      <div role = "main" class = "ui-content">
         <div data-demo-html = "true" data-demo-js = "#extension">
            <div data-role = "popup" id = "alignment_popup" class = "ui-content">
               <form data-role = "fieldset">
                  <div>
                     <label for = "xalign">X Alignment</label>
                     <input type = "range" id = "x-axis" value = "0.5" min = "1" max = "3" 
                        step = "0.5">
                  </div>
                  
                  <div>
                     <label for = "yalign">Y Alignment</label>
                     <input type = "range" id = "y-axis" value = "0.5" min = "1" max = "3" 
                        step = "0.5">
                  </div>
               </form>
            </div>
         </div>
         
         <a href = "#alignment_popup" id = "alignment_popup1" data-rel = "popup" 
            role = "button" 
            class = "ui-btn ui-btn-inline">Click to Open Popup</a>
      </div>
   </body>
</html>

输出

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

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

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

❮ jQuery Mobile - 小部件