Last active
August 29, 2015 14:25
-
-
Save galulex/98161dac26151046e6a3 to your computer and use it in GitHub Desktop.
zoom
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
$(document).on('mousemove', '.zoom', function (e){ | |
var rect = e.target.getBoundingClientRect(), | |
offsetX = e.clientX - rect.left, | |
offsetY = e.clientY - rect.top; | |
x = offsetX/this.offsetWidth*100 | |
y = offsetY/this.offsetHeight*100 | |
this.style.backgroundPosition = x + '% ' + y + '%'; | |
}) | |
$(document).on('mouseenter', '.zoom', function (e){ | |
this.style.backgroundImage = 'url(' + $(this).find('img').attr('src') + ')'; | |
}) | |
$(document).on('mouseleave', '.zoom', function (e){ | |
this.style.backgroundImage = ''; | |
}) |
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
.zoom img { | |
transition: opacity .5s; | |
&:hover { | |
opacity: 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment