gpt4 book ai didi

javascript - jQuery scrollTop() 在移动浏览器上滚动 DIV 时不起作用,替代方案?

转载 作者:IT王子 更新时间:2023-10-29 03:20:47 26 4
gpt4 key购买 nike

我正在尝试滚动到滚动 DIV 中的特定位置。现在我正在使用 jQuery scrollTop() 函数的像素偏移,它在桌面浏览器上运行良好,但它在 android 移动浏览器上不起作用,除了 Google 的 Chrome Android 浏览器(没有 iOS 设备来测试它是否有效) ).我找到的所有解决方案都是用于页面(窗口)滚动,而不是用于在 DIV 中滚动,有人对我可以用来完成相同任务的其他方法有任何建议吗?

这是一个例子:
http://jsfiddle.net/aQpPc/
http://jsfiddle.net/aQpPc/embedded/result/

我尝试过的在桌面浏览器中工作的其他东西:

document.getElementById('ID_of_element_in_a_DIV').scrollIntoView();
document.getElementById('ID_of_DIV').scrollTop = 200;

2013 年 3 月 11 日编辑:

这是一个已知的 android 浏览器问题:https://code.google.com/p/android/issues/detail?id=19625

错误报告中的一位用户提出了一种解决方法:

because the issue only seems to appear when the overflow property is set to scroll, you can first set it to 'hidden', set the scrollTop property, then reset it back to 'scroll' (or auto). The scrollTop property seems to be honored when the element is re-rendered with scrollbars. It's not clear if this has any unexpected side-effects, but "it works on my machine!"

最佳答案

这对我有用:

setTimeout( function() {
$(div).scrollTop(0)
}, 500 );

关于javascript - jQuery scrollTop() 在移动浏览器上滚动 DIV 时不起作用,替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12225456/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com