Skip to content Skip to sidebar Skip to footer

Prevent Page From Scrolling To Top

I have a little problem with jQuery Mobile and anchor link's by url. When page is load, after jquery throw event's work fine, but then jquery execute code and move page to top of p

Solution 1:

The default behavior of jQuery Mobile when showing pages is to scroll to top upon showing a page. The value of scroll is always 0 and stored in $.mobile.defaultHomeScroll.

You need to override this value on any page event but before page is totally shown and transition is done.

if (location.hash == "#wopwop") { 
  $.mobile.defaultHomeScroll = $('#wopwop').offset().top; 
}

This will force scrolling to wopwop div's offset in page without scrolling to top and then back to that div.

Solution 2:

$(document).ready(function(){
    $('html, body').animate({ scrollTop: $("#wopwop").offset().top }, 7000);
});

Post a Comment for "Prevent Page From Scrolling To Top"