Samuel Rossille
Samuel Rossille

Reputation: 19888

How to find out if a mouse-down event occurred on the scroll-bar or anywhere else in the element?

I have a HTML div which as use as a canvas that contains many objects.

In this canvas, the user can draw a rectangle with the mouse to select the objects. There is a flaw in my implementation: if the canvas is too large and scroll-bar appear, dragging the scrollbars also draws a selection rectangle.

What would be a good approach to discriminate mouse down on the scroll-bar, and mouse-down anywhere else on the component ?

Edit: I'm not asking how to remove the scrollbars. I want them when they are needed

Edit: Here is a minimal fiddle to reproduce the issue I'm working on: http://jsfiddle.net/jUe8T/

Upvotes: 0

Views: 442

Answers (1)

Ties
Ties

Reputation: 5846

THe fiddle was very helpfull as i though you were using the <canvas> element... i think this is what you want: http://jsfiddle.net/jUe8T/1/

i did this by adding a .scroll event to $('#canvas') with upHandler as handler, like this:

$('#canvas').scroll(upHandler);

Upvotes: 1

Related Questions