Ben Muircroft
Ben Muircroft

Reputation: 3034

How do I use pointer-events to react only to scroll event?

Is it possible to set pointer-events to only react to scrolling or drag on a touch-pad? I have a div 'in the way' for scrolling a complex html arrangement* and I would like to know if I can limit the pointer events to only react to scroll / mouse wheel actions.

I am interested in knowing whether I understand this correctly. If pointer-events:none; means that all events are void, how can I kill all events but leave one active?

I have set up an HTML area that is bigger than the box it fits in, but if I were to show the scroll bar, it would seem higher than it should be because of a pop-up (position:top) element. This area still needs to be scrolled so to achieve this I have used jQuery to make my 'box to scroll' follow an invisible div within a div:

<div id="scrollcontrol"style="overflow-y:auto;overflow-x:hidden;position:absolute;
   top:12px;left:180px;width:40px;height:1300px;">
   <div id="catscrollpos"style="position:absolute;
    top:0px;width:200px;height:2250px;">
   </div>
</div>

Script

$('#scrollcontrol').scroll(function({
  $('#rangetable').css({
  'top':$('#catscrollpos').position().top+'px'
  });
});

Upvotes: 50

Views: 42587

Answers (2)

Muthu
Muthu

Reputation: 83

Today I also faced same issue. I want to disable click events but allow scroll.

My Old code:

<div style="width: 100%; height: 540px; overflow: auto; pointer-events: none;">
<table></table>
</div>

I cannot able to scroll because of pointer-events: none; So I have added overflow to div element and pointer-event to table element. It fixed the scroll problem.

Solution:

<div style="width: 100%; height: 540px; overflow: auto">
<table style="pointer-events: none;"></table>
</div>

Upvotes: 1

GibboK
GibboK

Reputation: 73918

As for specification in the docs:

When an element has applied pointer-events: none;

The element is never the target of any mouse events and any events are void;

Please look at this demonstration:

http://jsbin.com/wewosumehi/1/

Events are not being fired, you cannot even scroll the container.

Upvotes: 1

Related Questions