前言
js制作放大镜是非常经典的案例,在很多地方也非常常见,例如商品的查看,我也整理了一些自己以前使用过的方法,仅供参考学习。
一、放大镜案例
方法一
第一种方法较为常见,也更容易理解
代码如下(示例):
<style>
.box {
position: relative;
height: 398px;
width: 398px;
border: 1px solid #ccc;
}
.mask {
display: none;
position: absolute;
top: 0;
left: 0;
width: 300px;
height: 300px;
background: #ccc;
opacity: .5;
border: 1px solid #ccc;
cursor: move;
}
.big {
display: none;
position: absolute;
left: 410px;
top: 0;
width: 500px;
height: 500px;
z-index: 999;
border: 1px solid #ccc;
overflow: hidden;
}
.big img {
position: absolute;
width: 600px;
height: 600px;
top: 0;
left: 0;
}
</style>
</head>
<body>
<div class="box">
<img src="1.png" alt="">
<div class="mask"></div>
<div class="big">
<img src="1.png" alt="" class