Created
December 7, 2014 01:15
-
-
Save yratof/ac6a060a1121ba608073 to your computer and use it in GitHub Desktop.
JS - Eye follows mouse
This file contains hidden or 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
$( document ).on( "mousemove", function( event ) { | |
var mousePosition = {}; | |
mousePosition.x = event.pageX; | |
mousePosition.y = event.pageY; | |
$(".eye").each(function(index,element){ | |
eyePosition = $(this).offset(); | |
angle = Math.atan2(mousePosition.y - eyePosition.top, mousePosition.x - eyePosition.left); | |
translateX = 10 * Math.cos(angle); | |
translateY = 10 * Math.sin(angle); | |
$(this).attr("transform", "translate("+ translateX +" "+ translateY+")"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment