Skip to content

Instantly share code, notes, and snippets.

@loginx
Created November 20, 2012 20:29
Show Gist options
  • Save loginx/4120852 to your computer and use it in GitHub Desktop.
Save loginx/4120852 to your computer and use it in GitHub Desktop.
jQuery containsPoint method
# jQuery method to detect whether or not a point (x,y) is within the bounds of a jQuery element.
# Example usage: $("#container").containsPoint 100, 100
$.fn.containsPoint = (x, y) ->
(@offset.left < x < @offset.left + @width()) and
(@offset.top < y < @offset.top + @height())
// jQuery method to detect whether or not a point (x,y) is within the bounds of a jQuery element.
// Example usage: $("#container").containsPoint(100, 100)
$.fn.containsPoint = function(x, y) {
return ((this.offset.left < x && x < this.offset.left + this.width())) && ((this.offset.top < y && y < this.offset.top + this.height()));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment