jquery mobile 加载完成后,自动返回顶部

在html5开发中,发现这么一个问题:每次返回上一个页面时,总是返回到上一个页面的顶部。大部分时间是无所谓的,但是如果遇到列表比较长时,体验就很糟糕了。所以得想办法解决这个问题。

花了很长时,查了很多资料都没有发现问题出在哪。最后通过断点调试,发现问题出在jquery mobile在页面加载完成后,会自动调用silentScroll函数

window.scrollTo( 0, ypos );
,所以会出现上述问题。

<span style="white-space:pre">			</span>$.event.special.scrollstart.enabled = false;

			setTimeout(function() {
				window.scrollTo( 0, ypos );
				$.mobile.document.trigger( "silentscroll", { x: 0, y: ypos });
			}, 20 );

			setTimeout(function() {
				$.event.special.scrollstart.enabled = true;
			}, 150 );

通过查找,发现调用语句是:

// window load event
// hide iOS browser chrome on load if hideUrlBar is true this is as fall back incase we were too early before
if ( $.mobile.hideUrlBar ) {
$window.load( $.mobile.silentScroll );
}


目前的解决方案是注释掉$window.load( $.mobile.silentScroll );,就能达到想要效果了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值