jQuery: How do I scroll the body without showing t

2019-09-13 00:01发布

问题:

I'm trying to hide the scroll bar of the document (in some browsers it's the body element, in others it's the html element) by using overflow:hidden;. Then i'm using jQuery.animate() to try and animate the scrollTop property. It works fine when the scroll bar is visible (i.e. without the overflow:hidden; style) but doesn't work when the scroll bar is hidden. Why is that? I'll be able to post a link to a snapshot of the problematic page in a bit...

回答1:

Try make <body> overflow:hidden and animate the margin-top property, note the margin-top should be negative if you want a positive scrollTop.

On webkit you could use ::-webkit-scrollbar: { display: none; } to hide the scrollbar with scroll features enabled.