Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is wheel scrolling event not firing when mouse is over a "position: fixed" element?

Here is a simple test case for my problem :

http://jsfiddle.net/JZmvf/20/

  • put mouse over the red square
  • scroll with mouse wheel
  • the parent div is not scrolling

How to make the parent div normally scroll with mouse wheel, even when the mouse is over the position: fixed element ?

Thanks.

like image 276
user1709931 Avatar asked Sep 30 '12 15:09

user1709931


People also ask

Why is my scroll wheel not moving?

The most typical causes of a mouse that will not scroll are two difficulties. The first is that dust and grime clog the mouse wheel, causing mechanical problems. The second issue is that wireless mice have poor battery life.

Which event is called when a mouse wheel scrolls?

The onwheel event occurs when the mouse wheel is rolled up or down over an element. The onwheel event also occurs when the user scrolls or zooms in or out of an element by using a touchpad (like the "mouse" of a laptop).


2 Answers

Its very late for an answer but I was able to overcome this problem by adding pointer-events: none style to the "fixed" div.

Like this: http://jsfiddle.net/JZmvf/55/

like image 181
Vivek Avatar answered Sep 29 '22 20:09

Vivek


Elements with position: fixed; are positioned relative to the viewport, so the scrollable div is not the parent of the fixed div in this case, even though it may appear that way if you're just looking at the output.

If you position your cursor over the fixed div and scroll down, your browser is being told to scroll down the fixed div. Fixed elements, by nature, are not scrollable, so nothing happens.

You may want to add a few more details about exactly what you're trying to accomplish. Hope that helps!

like image 37
zakangelle Avatar answered Sep 29 '22 19:09

zakangelle