Skip to content

Instantly share code, notes, and snippets.

@dpmango
Created July 19, 2017 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpmango/b849907643fbe356d20c17c74565c33e to your computer and use it in GitHub Desktop.
Save dpmango/b849907643fbe356d20c17c74565c33e to your computer and use it in GitHub Desktop.
// hero parallax on mousemove
var movementStrength = 50;
var height = movementStrength / _window.height();
var width = movementStrength / _window.width();
$(".hero").mousemove(function(e){
var pageX = e.pageX - (_window.width() / 2);
var pageY = e.pageY - (_window.height() / 2);
var newvalueX = width * pageX * -1 - 25;
var newvalueY = height * pageY * -1 - 50;
$('.hero-bg').css("background-position", newvalueX+"px "+newvalueY+"px");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment