Skip to content

Instantly share code, notes, and snippets.

@jamespantalones
Created January 19, 2015 11:53
Show Gist options
  • Save jamespantalones/6baefdf2c9690e0260e1 to your computer and use it in GitHub Desktop.
Save jamespantalones/6baefdf2c9690e0260e1 to your computer and use it in GitHub Desktop.
Giant Hand Cursor
//get previous position, so hand doesn't jump on route changes
var xPos = 0;
var yPos = 0;
var storePos = function(x,y){
xPos = x;
yPos = y;
};
var getPos = function(){
var positions = {
x: xPos,
y: yPos
};
return positions;
};
// Public API here
return {
storePos: function (x,y) {
storePos(x,y);
},
getPos: function(){
return getPos();
}
};
//hand movements
var frame = $('#main-frame');
var pos = mousePosition.getPos();
var xPos = pos.x;
var yPos = pos.y;
//set initial css based on prev position, add 10px for offset
element.css({
left: xPos + 10,
top: yPos + 10
});
//listen for changes
frame.on('mousemove', function(e){
xPos = e.pageX;
yPos = e.pageY;
element.css({
left: xPos + 10,
top: yPos + 10
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment