Reputation: 10681
Using jquery Mobile, I'm trying to scroll to an #id towards the middle of the page when the entire page is finished loading. So, when the user gets to the page, the user is at top the top of the page, and then scrolls very quickly to #example.
Using the $mobile.silentScroll, it doesn't seem to be firing at all.
$('#page').live( 'pageinit', scrollDown);
function scrollDown() {
var myDivPos = $('#example').offset().top;
$.mobile.silentScroll( myDivPos );
}
What would be the best way to accomplish a smooth scroll to $('#example') on mobile phone? I've tried the scrollTo plugin, which works on the desktop version of my mobile site, but not on a mobile device.
Upvotes: 0
Views: 15033
Reputation: 50767
Animating is fully supported in jQuery Mobile and any mobile device that supports jQuery. that being said, we can catch the offset.top of the example and use it to get the page to scroll.
A working jsFiddle has been included, but the code is minimal and is posted below:
$(function(){
$('html, body').animate({
scrollTop: $('#example').offset().top
});
});
Hope it helps.
Upvotes: 11