Created
August 26, 2015 21:27
-
-
Save amurrell/5f8a2e7aea9d5c1df01c to your computer and use it in GitHub Desktop.
Check Mouse Position on 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
// Alter the logic for bounds to detect :after or :before pseudo elements. | |
var checkMousePosition = function(element, e) { | |
var h = element.outerHeight(), | |
w = element.outerWidth(), | |
top = element.offset().top, | |
left = element.offset().left, | |
inY = e.pageY !== undefined && ( e.pageY >= top && e.pageY <= (top + h) ), | |
inX = e.pageX !== undefined && ( e.pageX >= left && e.pageY <= (left + w) ); | |
if (inY && inX) { | |
console.log('in'); // do whatever you want here, or choose to return a value. | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment