Last active
June 5, 2019 13:35
-
-
Save AndersDJohnson/5882475 to your computer and use it in GitHub Desktop.
jQuery event ratio 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.ratioOffsets(e); | |
console.log(e.ratioOffsetX, e.ratioOffsetY); | |
}); |
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
// depends on $.event.normalizeOffsets | |
// see https://gist.github.com/AndersDJohnson/5882463 | |
$.event.ratioOffsets = function (e) { | |
$.event.normalizeOffsets(e); | |
var $target = $(e.target); | |
e.ratioOffsetY = e.normalizedOffsetY / $target.height(); | |
e.ratioOffsetX = e.normalizedOffsetX / $target.width(); | |
return e; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment