如何滚动到jQuery Mobile中的页面元素? [英] How can I scroll to a page element in jQuery Mobile?
本文介绍了如何滚动到jQuery Mobile中的页面元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个很长的jQuery移动页面,并希望在页面加载后滚动到该页面下半部的一个元素.
I have a long jQuery mobile page and would like to scroll to an element halfway down this page after the page loads.
到目前为止,我已经尝试了一些方法,最成功的是:
So far I've tried a few things, the most successful being:
jQuery(document).bind("mobileinit", function() {
var target;
// if there's an element with id 'current_user'
if ($("#current_user").length > 0) {
// find this element's offset position
target = $("#current_user").get(0).offsetTop;
// scroll the page to that position
return $.mobile.silentScroll(target);
}
});
这可行,但是当DOM完全加载后,页面位置将重置.谁能建议一种更好的方法?
This works but then the page position is reset when the DOM is fully loaded. Can anyone suggest a better approach?
谢谢
推荐答案
您要查找的事件是"pageshow".
The event you're looking for is "pageshow".
这篇关于如何滚动到jQuery Mobile中的页面元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文