Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement