jQuery Mobile - Popup Alignment



Description

Sets the alignment along with x-axis or y-axis for the popup in a page.

Example

Following example demonstrates the use of popup alignment in the jQuery Mobile Framework.

<!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>

Output

Let's carry out the following steps to see how the above code works −

  • Save the above html code as jqm_popup_alignment.html file in your server root folder.

  • Open this HTML file as http://localhost/jqm_popup_alignment.html and the following output will be displayed.

jquery_mobile_widgets.htm
Advertisements