当前位置:网站首页>DOM操作---放大镜案例
DOM操作---放大镜案例
2022-08-02 03:22:00 【cjx177187】
在box盒子中设置图片为背景,在盒子中设置一个move小盒子;给move盒子绑定移动事件,使其随着鼠标运动;设置一个盒子max与move盒子成比例放大作为放大后显示的窗口,在max盒子中添加一个图片,给图片设置成与box盒子背景图成比例放大的宽高;将图片在max盒子中超出部分隐藏;每次移动mova盒子时,修改max盒子中的img的top和left使其与move盒子移动成倍的距离
注意:
- 每个盒子成比例缩放,
- 每个盒子都要固定定位,不然top和left不能生效。
- 再放大显示时,窗口时动不了的,这时就只能移动图片,使其往move盒子移动的反方向运动。
<style>
.a{
display: flex;
justify-content: flex-start;
}
.box{
width: 200px;
height: 310px;
background-image: url("https://p0.ssl.qhimgs1.com/sdr/400__/t01043eec7c54708f40.jpg");
background-size: 100%;
position: relative;
}
.move{
width: 40px;
height: 40px;
background-color:rgb(89, 93, 93,0.5);
position: absolute;
display: none;
}
.show{
width: 120px;
height: 120px;
position:relative;
display: none;
overflow: hidden;
margin: 100px;
border: 1px solid black;
}
img{
width: 400px;
height: 620px;
position: absolute;
}
</style>
<div class="a">
<div class="box">
<div class="move"></div>
</div>
<div class="max">
<div class="show">
<img src="https://p0.ssl.qhimgs1.com/sdr/400__/t01043eec7c54708f40.jpg" alt="">
</div>
</div>
</div>
<script>
var box=document.querySelector(".box")
var move=document.querySelector(".move")
var show=document.querySelector(".show")
var img=document.querySelector("img")
box.addEventListener("mouseover",function(el){
move.style.display="block"
show.style.display="block"
})
box.addEventListener("mouseout",function(){
show.style.display="none"
move.style.display="none"
})
box.addEventListener("mousemove",function(el){
//在小图片上使move小盒子随鼠标移动
move.style.top=el.clientY-20+"px"
move.style.left=el.clientX-20+"px"
//窗口动不了,将图片移动
img.style.top=-(el.clientY-20)*2+"px"
img.style.left=-(el.clientX-20)*2+"px"
})
</script>
边栏推荐
猜你喜欢
磷脂-聚乙二醇-酰肼,DSPE-PEG-Hydrazide,DSPE-PEG-HZ,MW:5000
parser = argparse.ArgumentParser() parsing
Phospholipid-Polyethylene Glycol-Aldehyde DSPE-PEG-Aldehyde DSPE-PEG-CHO MW: 5000
PowerManagerService灭屏超时流程
云服务器安装部署Nacos2.0.4版本
MySQL常见的索引
手把手带你 Unity 入门之从零创建一个时钟(GameObjects 与 Scripts)
APK的安装过程分析 PMS包管理器
Cloud server installation and deployment of Nacos 2.0.4 version
STM32 触发HardFault_Handler如何查找原因
随机推荐
每天填坑,精卫填坑第二集,TX1 配置从固态启动,安装Pytorch
PCL—point cloud data segmentation
ThunderBirde无法登录问题、pycharm调试一直收集数据、RuntimeError: CUDA error: device-side assert triggered等疑难杂症解决
mysql中json类型字段用法
[详解C语言]一文带你玩转C语言小游戏---三子棋
C语言中关于2的n次方求值问题(移位运算)
parser = argparse.ArgumentParser() parsing
Problems when yolov5 calls ip camera
Amazon sellers how to improve the conversion
np.unique()函数
PowerManagerService灭屏超时流程
C语言 0长度数组/柔性数组
Phospholipid-polyethylene glycol-hydrazide, DSPE-PEG-Hydrazide, DSPE-PEG-HZ, MW: 5000
Knowledge Engineering Assignment 2: Introduction to Knowledge Engineering Related Fields
oracle内连接和外连接
DSPE-PEG-DBCO Phospholipid-Polyethylene Glycol-Dibenzocyclooctyne A Linear Heterobifunctional Pegylation Reagent
A senior test engineer asked me these questions as soon as the interview came
HCIP-第十一天-MPLS+BGP
Phospholipid-polyethylene glycol-targeted neovascularization targeting peptide APRPG, DSPE-PEG-APRPG
SSM integration