网络编程 发布日期:2025/11/1 浏览次数:1
本文实例为大家分享了js仿京东放大镜效果的具体代码,供大家参考,具体内容如下
1、效果1:鼠标经过前
2、效果2:鼠标放上去,弹出右边放大镜
3、效果3:鼠标在小盒子移动,放大镜跟着移动
4、源代码如下:
<!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: 0;
padding: 0;
}
/* 左边小盒子样式 */
.box1{
position: relative;
width: 450px;
height: 450px;
border: 1px solid #999;
margin-left: 80px;
margin-top: 50px;
}
.box1 .img1{
/* 设置左边图片大小 */
width: 450px;
}
/* 遮罩层bg的样式 */
.box1_bg{
/* 一开始要隐藏起来 */
display: none;
position: absolute;
top: 0;
left: 0;
width: 300px;
height: 300px;
background-color: yellow;
/* 透明效果 */
opacity: .5 ;
cursor: move;
}
/* 右边大盒子样式 */
.big_img{
/* 一开始要隐藏起来 */
display: none;
width: 540px;
height: 540px;
position: absolute;
top: 0;
left: 470px;
border: 1px solid #999;
overflow: hidden;
}
/* 大盒子里面的图片样式 */
.big_img .big_imgs{
position: absolute;
top: 0;
left: 0;
width: 800px;
}
</style>
</head>
<body>
<div class="box1">
<img class="img1" src="/UploadFiles/2021-04-02/2-1.jpg">
5、喜欢的话记得点赞 收藏 关注噢~
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。