-Webkit滚动条+溢出+ JQuery scrollTop总是返回零 [英] -Webkit-scroll bar + overflow + JQuery scrollTop returns always zero
问题描述
我一整天都在处理这个bug,无法解决它。
有一个JQuery scrollTop动画脚本,它检测$(窗口).scrollTop()值,并做一些动画,如果点击按钮滚动回到顶部。
$(this).click(function(){
$(html,body)。animate({scrollTop:0},fast);
} p>
这样工作正常。和我总是得到一个scrollTop值...直到 - >
当使用自定义-webkit滚动条为您的浏览器,你必须
设置在css
html - > overflow:hidden
body - > position:absolute,overflow-y :scroll,overflow-x:auto
html层次结构只是正常的html-> body-> div container - > div content等。
现在,由于浏览器滚动条已删除,并且有自己的自定义滚动条,
scrollTop值总是返回零。
一直尝试所有我可以想到,无论其他代码我试过,scrollTop的值总是返回零。
没有什么是动画,没有什么是回滚。
任何人都知道如何获得
-webkit-scrollbar >
您不再滚动窗口,您正在滚动内部元素,因此您应该尝试:
$(html).scrollTop()
$(body).scrollTop()
看是否有变化
I've been working on this bug whole day, and couldn't solve it.
Have a JQuery scrollTop animation script, that detects $(window).scrollTop() value and do some animation and if click on button scrolling back to top. $(this).click(function() { $("html, body").animate({scrollTop:0},"fast"); });
This works normally great. and i always get a scrollTop value... Until ->
When using custom -webkit-scroll bar for your browser, you have to set in the css
html -> overflow: hidden body -> position: absolute, overflow-y:scroll, overflow-x:auto
the html hierarchy is just normal html->body-> div container - > div content etc.
Now since the browser scrollbar is removed, and have your own customized scrollbar, the scrollTop value always returns zero.
Have been trying all I can think of, no matter what other code I tried, the scrollTop value returns always zero.
So nothing is animating, and nothing is scrolling back.
Anybody know how to get the value when using the custom *browser -webkit-scrollbar for scrolling back to top?*
You're no longer scrolling the window, you're scrolling an internal element, so you should try:
$(html).scrollTop()
$(body).scrollTop()
and see if 0 changes
这篇关于-Webkit滚动条+溢出+ JQuery scrollTop总是返回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!