Created
March 13, 2015 22:03
-
-
Save UziTech/6bf3c1a3de4e09226db1 to your computer and use it in GitHub Desktop.
jQuery plugin to check if a point on the page is within an element.
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
/* | |
* DWTFYW License | |
* | |
* Author: Tony Brix, http://tonybrix.info | |
* | |
* Check if a point is within an element. | |
* Useful for mouseover on absolutely positioned overlapping elements. | |
* | |
* Example: | |
* $(document).mousemove(function(e){ | |
* if($("#element").isOver(e.pageX, e.pageY)){ | |
* alert("Mouse is over element."); | |
* } | |
* }); | |
*/ | |
(function ($) { | |
$.fn.isOver = function (x, y) { | |
var result = false; | |
this.each(function () { | |
var $this = $(this); | |
var top = $this.offset().top; | |
var bottom = $this.outerHeight() + top; | |
var left = $this.offset().left; | |
var right = $this.outerWidth() + left; | |
result = (x > left && x < right && y < bottom && y > top); | |
if (result) { | |
return false; | |
} | |
}); | |
return result; | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment