Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Jquery-popup is to wide at mobiles

jjdk

Coder
Hi.
I have a contact form that I have made responsive.
But I have problem with a Jquery-popup, when it's shown at mobiles. It's to wide because width is set to 800px.

Is it possible to set the width according to the width of the device.

My javascript code:
JavaScript:
$( document ).ready(function() {
        $(".formaal").change(function(){
            update_formaal();
        });
        $(".formaal").keyup(function(){
            update_formaal();
        });
        $( "#dialog" ).dialog({
            autoOpen: false,
            width: 800,
            buttons: {
            "Ok": function() {
              $( this ).dialog( "close" );
            }
          }
        });
        $( "#formaal_text" ).click(function() {
        $( "#dialog" ).dialog( "open" );
        });
    });
 
Yes, it is possible to set the width of the popup according to the width of the device. You can use JavaScript to get the width of the viewport and use that value to set the width of the popup. Here's an updated version of your code:

javascript


JavaScript:
$( document ).ready(function() {
  $(".formaal").change(function(){
    update_formaal();
  });
  $(".formaal").keyup(function(){
    update_formaal();
  });
  $( "#dialog" ).dialog({
    autoOpen: false,
    width: $(window).width() * 0.8,
    buttons: {
      "Ok": function() {
        $( this ).dialog( "close" );
      }
    }
  });
  $( "#formaal_text" ).click(function() {
    $( "#dialog" ).dialog( "open" );
  });
});
 
I think I got it:
JavaScript:
    $( document ).ready(function() {
      $(".formaal").change(function(){
        update_formaal();
      });
      $(".formaal").keyup(function(){
        update_formaal();
      });
      
      var wi = $(window).width();
      if (wi > 2000) {
      $( "#dialog" ).dialog({
        autoOpen: false,
        width: 2000,
        buttons: {
          "Ok": function() {
            $( this ).dialog( "close" );
          }
        }
      });
      }
      else {
      $( "#dialog" ).dialog({
        autoOpen: false,
        width: $(window).width() * 0.95,
        buttons: {
          "Ok": function() {
            $( this ).dialog( "close" );
          }
        }
      });
          
      }
      
      $( "#formaal_text" ).click(function() {
        $( "#dialog" ).dialog( "open" );
      });
    });
 
Back
Top Bottom