Created
July 31, 2013 18:33
-
-
Save nola/6124790 to your computer and use it in GitHub Desktop.
mousePosition
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 mousePos; | |
var lastMousePos = {x:0, y:0}; | |
function initPanning () { | |
//TweenMax.ticker.addEventListener("tick", doPanning); | |
} | |
var moveRange = 20; | |
var halfRange = moveRange/2; | |
function doPanning () { | |
if ( !!mousePos && (lastMousePos.x != mousePos.x || lastMousePos.y != mousePos.y) ) { | |
var adjX = (mousePos.x/demoProps.w); | |
var adjY = (mousePos.y/demoProps.h); | |
var percX = (-(moveRange*adjX))+"%"; | |
var percY = (-(moveRange*adjY))+"%"; | |
TweenMax.set( $(".roomBox"), { left:percX, top:percY, overwrite: 1 } ); | |
lastMousePos.x = mousePos.x; | |
lastMousePos.y = mousePos.y; | |
} | |
} | |
$(".demo").on("mousemove", function (e) { | |
if ( !mousePos ) { | |
mousePos = { x:e.pageX - $(this).offset().left, y:e.pageY - $(this).offset().top }; | |
} else { | |
mousePos.x = e.pageX - $(this).offset().left; | |
mousePos.y = e.pageY - $(this).offset().top; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment