Scrollbar in div scroll instead of page scrollbar

2019-09-04 13:19发布

I was building my site I can came across a little problem. I have a div with a fixed height and overflow:auto;. The height of the website will adjust itself to fit the page perfectly so that you dont get a scrollbar. My question is: Can I pass through the scroll event that happends in the page and redirect it to the scrollbar ? So in other words, when I scroll, not the page, but the scrollbar inside my div has to move.

I hope I made myself clear, if not, please ask for some more information.

With kindly regards, Bob

FIXED: The solution Andy brought up worked like a charm! Thank you and thanks all of you for your suggestions ^^.

3条回答
何必那么认真
2楼-- · 2019-09-04 13:42

Here's an example of a possible solution:

http://jsfiddle.net/TTXqQ/

I'm using the Mousewheel Plugin

查看更多
虎瘦雄心在
3楼-- · 2019-09-04 13:44

This should work, I have used it in the past:

div {
        width:150px;
        height:150px;
        overflow:scroll;
    }
查看更多
\"骚年 ilove
4楼-- · 2019-09-04 13:47

I believe the only way to do this is by fixing the content of everything else on the page and positioning your div such that it is in the "window" framed by the fixed content. If you can post your HTML, we may be able to help more.

查看更多
登录 后发表回答