Created
January 4, 2013 20:21
-
-
Save dmongeau/4455650 to your computer and use it in GitHub Desktop.
Zoom on mouse position
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
var toggle = true; | |
function mouseFlicker(e) { | |
if(toggle) { | |
var multiplier = Math.round(Math.random()*1)+3; | |
var width = window.innerHeight*wish.imageRatio; | |
var height = window.innerHeight; | |
var newWidth = width*multiplier; | |
var newHeight = height*multiplier; | |
var mouseX = e.pageX*multiplier; | |
var mouseY = e.pageY*multiplier; | |
var halfWidth = window.innerWidth/2; | |
var halfHeight = window.innerHeight/2; | |
var top = mouseY-halfHeight; | |
if(top < 0) top = 0; | |
var left = mouseX-halfWidth; | |
if(left < 0) left = 0; | |
if((newHeight-top) < window.innerHeight) { | |
top = newHeight - window.innerHeight; | |
} | |
if((newWidth-left) < window.innerWidth) { | |
left = newWidth - window.innerWidth; | |
} | |
$('#wishes').css({ | |
'background-size' : newWidth+'px '+newHeight+'px', | |
'background-position' : '-'+left+'px -'+top+'px ' | |
}); | |
toggle = false; | |
} else { | |
$('#wishes').css({ | |
'background-size' : 'cover', | |
'background-position' : 'top left' | |
}); | |
toggle = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment