How to make a scrollbar placeholder

亡梦爱人 提交于 2019-12-03 14:24:11

How about this:

  • Determine the width of the scrollbar in the current browser
  • Set a content div to padding-right: scrollbar-width
  • Hide scroll on parent

and after the animation:

  • Remove padding-right on content
  • show scroll on parent

I made a demo: http://jsfiddle.net/cwolves/ezLfU/1/

I just looked at your site and thought of an alternative approach. If you're hiding the scrollbar with overflow:hidden, you could also reimplement scrolling as well.

Attach events to page up/page down/home/end/arrow up/arrow down, mouse wheel up/mouse wheel down, and then do

$(window).scrollTop($(window).scrollTop() + 15)

The code above is obviously bad and just an example, but possibly something you may like to try.

How about making your content a few pixels less wide than the container and toggling the overflow-y attribute?

Scrollbars can have different widths on different browsers/OSes. If you are not going to calculate the width of the scrollbar you best take it wide enough so it works on all browsers.

Example

You can use http://jscrollpane.kelvinluck.com/ to give you some control over the scrollbar and work from that.

Displaying a disabled scrollbar is as simple as setting overflow:scroll;

Vertical only would be overflow-y:scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!