Last active
June 5, 2019 13:35
-
-
Save AndersDJohnson/5882463 to your computer and use it in GitHub Desktop.
jQuery event normalize offsets
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
$('.area').on('mousemove', function (e) { | |
$.event.normalizeOffsets(e); | |
console.log(e.normalizedOffsetX, e.normalizedOffsetY); | |
}); |
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
$.event.normalizeOffsets = function (e) { | |
var offset = $(e.target).offset(); | |
e.normalizedOffsetX = e.pageX - offset.left; | |
e.normalizedOffsetY = e.pageY - offset.top; | |
return e; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment