Created
April 7, 2018 19:46
-
-
Save luislobo14rap/924466c1d340bbd7a473c988978bf116 to your computer and use it in GitHub Desktop.
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
function mouseMoving(element, movementSpeed = 1) { | |
if (typeof element == 'string') { | |
element = $(element); | |
}; | |
element.css({ | |
'position': 'relative' | |
}); | |
$(document).on('mousemove', function(event) { | |
let x = event.pageX * 100 / $(document).innerWidth(); | |
let y = event.pageY * 100 / $(document).innerHeight(); | |
x = Number(x.toFixed(2) - 50); | |
y = Number(y.toFixed(2) - 50); | |
element.css({ | |
'left': x * movementSpeed, | |
'top': y * movementSpeed | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment