I currently use jTemplates to create a rather large table on the client, each row has a button that will open a jQuery UI dialog. However, when I scroll down the page and click on one of those buttons, jQuery dialog will open, but the scroll position get lost and the page jumps back to the top (with the blocking and the actual dialog showing off the screen). Has anyone seen or know what might cause this problem?
Thanks.
So, with jQuery, you can alternatively use this approach to prevent the default link behaviour: $('#ma_link'). click(function(e) { doSomething(); return false; }); If you're using raw DOM events, this will also work on modern browsers, since the HTML 5 spec dictates this behaviour.
Approach: A simple solution to this problem is to set the value of the “overflow” property of the body element to “hidden” whenever the modal is opened, which disables the scroll on the selected element.
Are you using an anchor tag to implement the "button" that pops the dialog? If so, you'll want the click handler that opens the dialog to return false so that the default action of the anchor tag isn't invoked. If you are using a button, you'd also need to make sure that it doesn't submit (by returning false from the handler) and completely refresh the page.
For example,
$('a.closeButton').click( function() { $('#dialog').dialog('open'); return false; }); <a class='closeButton'>Close</a>
If your buttons work with an html anchor tag with href="#"
replace the href for example by href="javascript:;"
or any other method that you use to disable the href. The reason why the scrolling happens is because of href="#"
scrolls to the top of your page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With