<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
padding: 0;
margin: o;
}
.main {
width: 800px;
}
.main .top {
position: relative;
display: flex;
}
.main .top .left {
position: relative;
;
width: 400px;
height: 400px;
background-color: bisque;
}
.main .top .left img {
width: 400px;
height: 400px;
}
.main .top .left .img2 {
display: none;
}
.main .top .left .mask {
position: absolute;
top: 0;
left: 0;
width: 200px;
height: 200px;
display: none;
background-color: rgb(223, 235, 164, 0.5);
}
.main .right {
position: relative;
display: none;
width: 400px;
height: 400px;
overflow: hidden;
border: 1p solid rgb(67, 61, 61);
}
.main .right img {
position: absolute;
top: 0;
left: 0;
width: 800px;
height: 800px;
}
.main .right .img4 {
display: none;
}
.main .bottom {
width: 400px;
background-color: beige;
}
.main .bottom .xxk {
display: flex;
list-style: none;
margin-top: 10px;
}
.main .bottom .xxk li:hover {
border: 1px solid lightcoral;
}
.main .bottom .xxk li img {
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div class="main">
<div class="top">
<div class="left">
<img src="./img/选项卡1.jpg" alt="" class="img1">
<img src="./img/选项卡3.jpg" alt="" class="img2">
<div class="mask"></div>
</div>
<div class="right">
<img src="./img/选项卡1.jpg" alt="" class="img3">
<img src="./img/选项卡3.jpg" alt="" class="img4">
</div>
</div>
<div class="bottom">
<ul class="xxk">
<li><img src="./img/选项卡1.jpg" alt=""></li>
<li><img src="./img/选项卡3.jpg" alt=""></li>
</ul>
</div>
</div>
<script>
var oLi = document.querySelectorAll(".xxk li");
var oImg = document.querySelectorAll(".left img");
var oImg2 = document.querySelectorAll(".right img");
var oLeft = document.querySelector(".left");
var oMask = document.querySelector(".mask");
var oRight = document.querySelector(".right");
// console.log(oLi);
// console.log(oImg);
// console.log(oImg2);
//选项卡
for (let i = 0; i < oLi.length; i++) {
oLi[i].onmouseover = function () {
for (var j = 0; j < oLi.length; j++) {
oImg[j].style.display = "none";
oImg2[j].style.display = "none";
}
oImg[i].style.display = "block";
oImg2[i].style.display = "block";
}
}
oLeft.onmouseover = function () {
oMask.style.display = "block";
oMask.style.cursor = "move";
oRight.style.display = "block";
oLeft.onmousemove = function (ev) {
var l = ev.clientX - oMask.offsetWidth / 2 - oLeft.parentElement.offsetLeft;
var r = ev.clientY - oMask.offsetHeight / 2 - oLeft.parentElement.offsetTop;
// console.log(r);
console.log(ev.clientY);
if (l <= 0) {
l = 0;
} else if (l >= oLeft.offsetWidth - oMask.offsetWidth) {
l = oLeft.offsetWidth - oMask.offsetWidth;
}
if (r <= 0) {
r = 0;
} else if (r >= oLeft.offsetHeight - oMask.offsetHeight) {
r = oLeft.offsetHeight - oMask.offsetHeight;
}
oMask.style.left = l + "px";
oMask.style.top = r + "px";
for (var a = 0; a < oImg2.length; a++) {
oImg2[a].style.left = -l * 2 + "px";
oImg2[a].style.top = -r * 2 + "px";
}
}
}
oLeft.onmouseout = function () {
oMask.style.display = "none";
oRight.style.display = "none";
}
</script>
</body>
</html>
js选项卡切换加放大镜
最新推荐文章于 2024-05-11 10:05:08 发布