Suppose I have two divs:
<div id="control"></div>
<div id="view">(A scrollable list)</div>
And I'd like to make it so that when the cursor is parked inside #control
and the mousewheel is scrolled, #view
will be scrolled instead. Anyway to achieve this?
Take a look to the last example -->
http://api.jquery.com/scroll/
not sure what the layout looks like
but if they're right next to each other you could use
and change a few things.
Here's a fiddle: http://jsfiddle.net/filever10/QVRNd/
If the elements are not able to be that close, this won't be much help.
It works by putting the control over the list, and disabling pointer events on the control.
Try the following solution. You could listen to event
mousewheel
on yourcontrol
div and scroll the other divview
based on the amount of scroll performed (value is retrieved usingWheelEvent.deltaY
);More information can be found here: https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaY
I tested this, and the only way I could achieve a
onscroll
event on a element is with an active scroll bar, which "floats". Explaining floats : it's position is at 100px from top, when it's scrolled we check if it went up or down, and then we bring it back to it's original position. So remember, you need an active scroll bar (the element's inner content should be higher than itself: you can use multiple<br>
etc...);Javascript code:
The CSS:
So, when you scroll inside
div1
, it checks if it was scrolled up/down, scrollsdiv2
up/down and sets div1 to it's default scroll value. Hope this trick helps.PS: You can make the scrollbars invisible if you make some research (
overflow:hidden
is not working because there won't be active scrollbars)This might help you:
Document has its function onscroll.
Let say
div1
to be scrolled and mouse pointer should be atdiv2
.So we have to execute the
scFunc()
only if the mouse is at div2. We can achieve this byOkay, quick fix that worked for me. Even though the fixed div is not scrollable, as it has no content to overflow its bounds, you can still detect
mousewheel
events.mousewheel
events contain deltas for the x/y dimensions scrolled.Note: This works for mice or track-pads, and will give you the proper direction (-/+), regardless of inverted Y-Axis settings (read: Apple's (un)natural scrolling)
Therefore, you can do something like this: