<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{margin: 0px; padding: 0px}
#ul1 li{list-style: none; width: 100px; height: 100px; border: 1px solid black; margin: 10px; float: left; background-color: gray}
#ul1{width: 366px; height: 366px;border: 1px solid black; margin: 100px auto; position: relative;}
#ul1 li img{width: 100%; height: 100%}
</style>
<script src="../startMove.js"></script>
<script>
window.onload = function(){
var ul = document.getElementById("ul1");
var lis = document.getElementsByTagName("li");
var currentIndex = 2;
for(var i = 0; i <lis.length; i ++){
lis[i].style.left = lis[i].offsetLeft + "px";
lis[i].style.top = lis[i].offsetTop + "px";
var img = document.createElement("img");
img.src = "img/" + (i + 1) + ".jpg";
lis[i].appendChild(img);
}
for(var i = 0; i < lis.length; i++){
lis[i].style.position = 'absolute';
lis[i].style.margin = '0px';
lis[i].onmouseover = function(){
this.style.zIndex = currentIndex++;
startMove(this,{
width: 200,
height: 200,
marginLeft: -50,
marginTop: -50
})
}
lis[i].onmouseout = function(){
startMove(this, {
width: 100,
height: 100,
marginLeft: 0,
marginTop: 0
})
}
}
}
</script>
</head>
<body>
<ul id = 'ul1'>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>
用JS实现多个图片的放大和缩小
最新推荐文章于 2023-11-28 15:16:11 发布