-
-
Save khripunovpp/13d4c1552ad5e183316102b12afbbac8 to your computer and use it in GitHub Desktop.
parallaxMouse
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
var parallaxMouse = function(el, coeff, direction) { | |
$(window).bind('mousemove', function(e) { | |
parallaxScroll(e); | |
}); | |
function parallaxScroll(e) { | |
$(el).each(function() { | |
var container = $('body'), | |
containerWidth = container.width(), | |
containerHeight = container.height(), | |
mouseXCord = event.pageX, | |
mouseYCord = event.pageY, | |
shiftX = containerWidth/2 - mouseXCord, | |
shiftY = containerHeight/2 - mouseYCord, | |
transformString; | |
if(direction === "x") { | |
transformString = 'transform: translateX(' + shiftX / (coeff*10) + '%)'; | |
} | |
if(direction === "y") { | |
transformString = 'transform: translateY(' + shiftY / (coeff*10) + '%)'; | |
} | |
if(direction === "xy") { | |
transformString = 'transform: translate(' + shiftX / (coeff*10) + '%, ' + shiftY / (coeff*10) + '%)'; | |
} | |
this.style = transformString; | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment