Scrollbar in div scroll instead of page scrollbar

2019-09-04 13:44发布

问题:

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 ^^.

回答1:

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

div {
        width:150px;
        height:150px;
        overflow:scroll;
    }


回答2:

Here's an example of a possible solution:

http://jsfiddle.net/TTXqQ/

I'm using the Mousewheel Plugin



回答3:

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.