scrollTo() 闪烁
我有一个动态页面,单击链接会触发一些 javascript,将某些页面元素设置为 display:none
,从而更改页面的高度。典型的浏览器行为是保留页面顶部的滚动位置。我想保留底部的滚动位置,因为链接位于页面底部附近,我希望用户的光标在单击后保留在链接上。
我必须执行此操作的代码是:(
var scrollBottom=getDocHeight()-getScrollTop();
//do stuff to change height
window.scrollTo(0,getDocHeight()-scrollBottom);
使用我发现的跨浏览器函数来获取文档高度和滚动位置)。
这在 Chrome 和 Internet Explorer 中工作正常,但在 Firefox 中,页面高度更改和滚动位置更改之间存在很小的延迟。结果,当页面快速重新调整时会出现闪烁,这让我很烦恼。
任何人都可以建议一种修复或更自然的方式来记住页面底部而不是顶部的滚动位置吗?
谢谢。
I have a dynamic page where clicking a link triggers some javascript that sets some page elements to display:none
, and thus changes the height of the page. The typical browser behavior for this is that the scroll position from the top of the page is retained. I want to retain the scroll position from the bottom instead, because the link is near the bottom of the page and I would like the user's cursor to remain over the link after it is clicked.
The code I have to do this is:
var scrollBottom=getDocHeight()-getScrollTop();
//do stuff to change height
window.scrollTo(0,getDocHeight()-scrollBottom);
(using cross-browser functions I found to obtain document height and scroll position).
This works fine in chrome and internet explorer, but in firefox, there is a small delay between the page height changing and the scroll position changing. As a result there is a flicker as the page quickly realigns itself, which is bothering me a great deal.
Can anyone suggest a fix or a more natural way to remember the scroll position from the bottom of the page instead of the top?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论