Skip to content

Instantly share code, notes, and snippets.

@Ivanopalas
Created August 17, 2016 14:44
Show Gist options
  • Save Ivanopalas/1d8ed040b59a3398081ec63a3678d7eb to your computer and use it in GitHub Desktop.
Save Ivanopalas/1d8ed040b59a3398081ec63a3678d7eb to your computer and use it in GitHub Desktop.
function parallax() {
var layer = $('.parallax').find('.parallax__layer');
$(window).on('mousemove', function (e) {
var mouseX = e.pageX;
var mouseY = e.pageY;
var w = (window.innerWidth / 2) - mouseX;
var h = (window.innerHeight / 2) - mouseY;
layer.map(function (key, value) {
var bottomPosition = (window.innerHeight / 2) * (key / 100);
var widthPosition = w * (key / 100);
var heightPosition = h * (key / 100);
$(value).css({
'bottom' : '-' + bottomPosition + 'px',
'transform' : 'translate3d(' + widthPosition + 'px, ' + heightPosition + 'px, 0)'
});
});
});
}
var layer = $('.parallax').find('.parallax__layer');
var width = window.innerWidth + 100;
layer.map(function (key, value) {
$(value).css({
'width' : width + 'px',
'margin-left': -(width / 2) + 'px'
})
});
parallax();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment