Created
November 20, 2012 20:29
-
-
Save loginx/4120852 to your computer and use it in GitHub Desktop.
jQuery containsPoint method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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