Created
May 12, 2014 21:14
-
-
Save rohitpaulk/4c643fb20674aaedbf1a to your computer and use it in GitHub Desktop.
jQuery Background Panning
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
| $('.panbg').mousemove(function(e){ | |
| //Let's find the midpoints of the screen | |
| var midpointX = $(window).width()/2 | |
| var midpointY = $(window).height()/2 | |
| //Now the pointer's deviation as a percentage. | |
| var mousePosX = ((e.pageX-midpointX)/$(window).width())*100; | |
| var mousePosY = ((e.pageY-midpointY)/$(window).height())*100; | |
| //Let's dilute it by a factor of 40 | |
| var xPos = mousePosX/40 + 50; | |
| var yPos = mousePosY/40 + 50; | |
| //Finally, let's move the background :) | |
| $('.panbg').css('backgroundPosition', xPos+'% '+ yPos+'%'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment