简体   繁体   English

设置浏览器滚动条的拇指位置

[英]Set the thumb position of the browser scrollbar

I've been working on a site that combines anchored scrolling with the normal scrolling, and so I've decided to have a part with a hidden scrollbar, and past a certain point have it be revealed. 我一直在一个将锚定滚动与普通滚动相结合的网站上工作,因此,我决定将一部分与隐藏的滚动条一起使用,并在某个特定点之前将其显示出来。 While I've managed to do this, the thumb of the scrollbar is not in the very top, as I'd like to, since of course the user has scrolled down. 虽然我设法做到了,但是滚动条的拇指并不是我想要的那样位于最顶部,因为用户当然已经向下滚动了。

Although, I know for certain this is possible as seen here , but checking out the javascript & css I don't really see how he's doing it. 虽然,我肯定可以在这里看到,但是查看javascript和css时,我并没有真正看到他的操作方式。

Thus I've come down to 2 options, one being hiding the scrollbar altogether and replacing it with a custom-made one, and the other one being having the anchored scroll section in fact be right over the normal scroll section and simply move away through some javascript animation (Might be hard to understand what I mean, but basically if you check out the link above it'll make more sense). 因此,我有两种选择,一种是完全隐藏滚动条,然后用定制的滚动条替换,另一种是将锚定的滚动条实际上​​放在普通滚动条的上方,然后简单地移开一些javascript动画(可能很难理解我的意思,但是基本上,如果您查看上面的链接,它将更有意义)。

Hope anyone can help give some insight on the matter! 希望任何人都可以帮助对此事提供一些见识!

When the page scrolls the body changes from 当页面滚动时,主体从

overflow: hidden;

to

overflow: auto;

overflow: hidden is the reason the scrollbar is hidden. overflow: hidden是滚动条被隐藏的原因。 You can use Javascript to detect scroll, or page position, and then make this style change to the body. 您可以使用Javascript检测滚动或页面位置,然后将此样式更改为正文。 There are also many scrolling plugins that will help you achieve this or similar. 还有许多滚动插件可以帮助您实现此目的或类似目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM