<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//at.alicdn.com/t/font_1763511_7owtuyag50u.css">
<style>
.contaier {
width: 400px;
margin: 0 auto;
}
.contaier img {
width: 100px
}
.show .imge {
z-index: 20;
position: absolute;
top: -108px;
left: 18%;
}
.cover {
width: 310px;
display: none;
height: 120px;
background-color: rgba(0, 0, 0, .3);
position: absolute;
top: -123px;
left: 0px;
}
em {
text-align: center;
position: absolute;
line-height: 18px;
right: 148px;
top: -108px;
display: inline-block;
width: 18px;
height: 18px;
background-color: red;
border: 1px solid black;
opacity: 0;
}
</style>
</head>
<body>
<div class="contaier">
<div class="wrap">
<img src="./img/1.jpg"> <img src="./img/2.jpg">
<img src="./img/3.jpg"> <img src="./img/4.jpg">
<img src="./img/5.jpg">
<img src="./img/6.jpg"></div>
<div class="show" style="position: relative;">
<div class="imge">
<img style="width: 160px;display: inline-block;" class="mback"></div>
<div class="cover"></div>
<em class="iconfont icon-cha"></em>
</div>
</div>
<script>
var imge = document.querySelectorAll('.wrap img')
var pic = document.querySelector('.mback')
var cover = document.querySelector('.cover')
var mback = document.querySelector('em')
var items = '';
imge.forEach(item => {
item.onclick = function () {
pic.src = item.getAttribute('src')
cover.style.display = 'block';
mback.style.opacity = '1';
}
})
mback.onclick = function () {
pic.src = '';//引用为空\有值 作为变换关键点
cover.style.display = 'none';
mback.style.opacity = '0';
}
</script>
</body>
</html>
图片放大镜
最新推荐文章于 2026-01-08 11:09:44 发布
1708

被折叠的 条评论
为什么被折叠?



