Skip to content

Instantly share code, notes, and snippets.

@nola
Created July 31, 2013 18:33
Show Gist options
  • Save nola/6124790 to your computer and use it in GitHub Desktop.
Save nola/6124790 to your computer and use it in GitHub Desktop.
mousePosition
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