A Pen by Captain Anonymous on CodePen.
Created
June 29, 2017 07:43
-
-
Save alukos/44fb30e8b5bcf39ceea27de50e85a199 to your computer and use it in GitHub Desktop.
NGJJeB
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
<img id="imgZoom" width="300px" height="200px" onmousemove="zoomIn(event)" onmouseout="zoomOut()" src="http://ginger-mum.com/wp-content/uploads/2015/10/3633-1269758855-0da5042c33400a811a5d766be4579cb8.jpg"> | |
<div id="overlay" onmousemove="zoomIn(event)"></div> |
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
function zoomIn(event) { | |
var element = document.getElementById("overlay"); | |
element.style.display = "inline-block"; | |
var img = document.getElementById("imgZoom"); | |
var posX = event.offsetX ? (event.offsetX) : event.pageX - img.offsetLeft; | |
var posY = event.offsetY ? (event.offsetY) : event.pageY - img.offsetTop; | |
element.style.backgroundPosition=(-posX*2)+"px "+(-posY*4)+"px"; | |
} | |
function zoomOut() { | |
var element = document.getElementById("overlay"); | |
element.style.display = "none"; | |
} |
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
#overlay{ | |
border:1px solid black; | |
width:350px; | |
height:200px; | |
display:inline-block; | |
background-image:url('http://ginger-mum.com/wp-content/uploads/2015/10/3633-1269758855-0da5042c33400a811a5d766be4579cb8.jpg'); | |
background-repeat:no-repeat; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment