<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
body,
div {
margin: 0;
padding: 0;
}
#box {
position: relative;
width: 480px;
margin: 20px auto;
}
#box img {
display: block;
float: left;
width: 100px;
height: 75px;
margin-left: 10px;
border: 5px solid #E6E6FA;
border-radius: 5%;
}
#mark {
box-sizing: border-box;
position: absolute;
margin-left: 10px;
width: 400px;
height: 300px;
border-radius: 5%;
}
@keyframes enter {
from {
width: 0;
height: 0;
}
to {
width: 400px;
height: 300px;
}
}
@keyframes leave {
from {
width: 400px;
height: 300px;
}
to {
width: 0;
height: 0;
}
}
#mark img {
width: 100%;
height: 100%;
margin-left: 0px;
}
</style>
</head>
<body>
<div id="box">
<img src="img/1.jpg" bigImg="img/1_bigger.jpg">
<img src="img/2.jpg" bigImg="img/2_bigger.jpg">
<img src="img/3.jpg" bigImg="img/3_bigger.jpg">
<img src="img/4.jpg" bigImg="img/4_bigger.jpg">
<div id="mark" style="display:none">
<img src="img/1_bigger.jpg">
</div>
</div>
<script type="text/javascript">
var box = document.getElementById("box");
var mark = document.getElementById("mark");
for (var i = 0; i < box.childNodes.length; i++) {
box.childNodes[i].onmouseenter = function(e) {
e = e || window.event;
e.target = e.target || e.srcElement;
mark.style.animation = "enter 0.8s";
if (mark.style.display == "none") {
mark.style.display = "block";
mark.style.left = e.clientX - box.offsetLeft + 10 + "px";
mark.style.top = e.clientY - box.offsetTop + 10 + "px";
var getNewSrc = e.target.getAttribute("bigImg");
mark.firstElementChild.setAttribute("src", getNewSrc);
}
}
box.childNodes[i].onmousemove = function(e) {
e = e || window.event;
mark.style.left = e.clientX - box.offsetLeft + 10 + "px";
mark.style.top = e.clientY - box.offsetTop + 10 + "px";
}
box.childNodes[i].onmouseleave = function(e) {
if (mark.style.display == "block") {
mark.style.display = "none";
}
}
}
</script>
</body>
</html>