I want my code to detect and trigger a custom function when user click within the coordinates of a rectangular.
IF the coordinates of Rectangle are already know.
I tried this code
W = $(el).width();
H = $(el).height();
X = $(el).position().left;
Y = $(el).position().top;
But not able to detect it.
Example
Consider this. I want to detect and trigger function within these coordinates.
http://www.mathopenref.com/coordrectangle.html
Getting mouse coordinates is easy:-
$('canvas').mousemove(function(e){
drawPaddle(e.pageX, e.pageY);
});
function drawPaddle(paddleX, paddleY) {
c.beginPath();
c.rect(paddleX, paddleY, 150, 10);
c.closePath();
c.fill();
}
How do I detect if user click within coordinates of my rectangle?