开发者

-Webkit-scroll bar + overflow + JQuery scrollTop returns always zero

开发者 https://www.devze.com 2023-02-06 18:00 出处:网络
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 scro

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


What happens when you remove overflow: hidden and position: absolute from your html and body CSS?


I believe this is a bug which hasn't been fixed yet completely. Check here https://bugs.webkit.org/show_bug.cgi?id=9248

and check the last comment which shows this demo (http://maisqi.com/outros/bugs/chrome/CHN6) which still fails in webkit based browsers.

0

精彩评论

暂无评论...
验证码 换一张
取 消