页面加载后jQueryMobile滚动到Div [英] jQueryMobile Scroll to Div after Page Loads

查看:56
本文介绍了页面加载后jQueryMobile滚动到Div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jquery Mobile,当整个页面加载完成时,我试图滚动到页面中间的#id.因此,当用户进入页面时,该用户位于页面顶部的顶部,然后非常快速地滚动到#example.

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.

使用$ mobile.silentScroll,它似乎根本没有触发.

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 );
}

在手机上平滑滚动至$('#example')的最佳方法是什么?我已经尝试过 scrollTo 插件,该插件可以在移动设备的桌面版本上使用网站,但不在移动设备上.

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.

推荐答案

完全支持jQuery Mobile和任何支持jQuery的移动设备.话虽如此,我们可以捕获示例的offset.top并使用它来使页面滚动.

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.

已包含有效的 jsFiddle ,但是代码很少,发布在下面:

A working jsFiddle has been included, but the code is minimal and is posted below:

$(function(){     
  $('html, body').animate({
    scrollTop: $('#example').offset().top
  });
});

希望有帮助.

这篇关于页面加载后jQueryMobile滚动到Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆