当前位置:网站首页>Magnifier case
Magnifier case
2022-06-26 02:14:00 【Asmruan】
<!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>
* {
margin: 0;
padding: 0;
}
header,
footer {
float: left;
border: 1px solid red;
width: 500px;
height: 500px;
overflow: hidden;
position: relative;
}
header img {
height: 500px;
width: 500px;
}
footer img {
height: 1100px;
width: 1100px;
}
#mask {
position: absolute;
left: 0px;
top: 0px;
width: 200px;
height: 200px;
background-color: rgba(1, 1, 1, 0.4);
}
</style>
</head>
<body>
<header>
<img id="smallImg" src="./images/1.jpg" alt="" />
<div id="mask"></div>
</header>
<footer>
<img id="bigImg" src="./images/1.jpg" alt="" />
</footer>
</body>
</html>
<script>
window.onload = function () {
var footer = document.querySelector("footer");
var header = document.querySelector("header");
var bigImg = document.querySelector("#bigImg");
var smallImg = document.querySelector("#smallImg");
var mask = document.querySelector("#mask");
// 1. Let the mask move with the mouse
// 2. Let the right side follow the scroll
// 1
header.onmousemove = function (event) {
var event = event || window.event;
// Mouse position subtract Half the mask width subtract The distance from the big box to the left subtract The left border of the big box
var maskLeft =
event.clientX -
mask.clientWidth / 2 -
header.offsetLeft -
header.clientLeft;
var maskTop =
event.clientY -
mask.clientHeight / 2 -
header.offsetTop -
header.clientTop;
// console.log(maskTop);
// console.log(top);
// Warning value
var maxLeft = header.offsetWidth - mask.clientWidth;
var maxTop = header.offsetHeight - mask.offsetHeight;
if (maskLeft >= maxLeft) {
maskLeft = maxLeft;
}
if (maskLeft <= 0) {
maskLeft = 0;
}
if (maskTop >= maxTop) {
maskTop = maxTop;
}
if (maskTop <= 0) {
maskTop = 0;
}
mask.style.left = maskLeft + "px";
mask.style.top = maskTop + "px";
// 2
var scrollLeft = maskLeft*2
footer.scrollLeft = scrollLeft
var scrollTop = maskTop*2
footer.scrollTop = scrollTop
};
};
</script>
边栏推荐
- 缓存技术之第一次亲密接触
- Tarte aux framboises + AWS IOT Greengrass
- SQL column value to row value (unpivot)
- Agent challenge - "Olympic running"
- Advanced cross platform application development (23): an article approaching the launch of testlight
- Shell curl execution script, with passed parameters and user-defined parameters
- shell curl 执行脚本,带传参数,自定义参数
- Cross server SQL connection configuration
- -- EGFR FISH probe solution
- Characteristics and related specificity of Papain
猜你喜欢
随机推荐
Redis linked list
Markov decision process (MDP): gambler problem
工作一年闲记
SDRAM Controller - add read / write FIFO
Keda 2.7.1 brief analysis of scaledjob code
Redis-SDS
shell curl 执行脚本,带传参数,自定义参数
Ardiuno智能电蚊拍
keda 2.7.1 scaledJob 代码简要分析
二分查找
Other codes,, VT,,, K
图形渲染管线
shell学习记录(三)
为 ServiceCollection 实现装饰器模式
Chrome浏览器开发者工具使用
Interface test case design
Prometeus 2.33.0 新特性
基於鄰接矩陣的廣度優先遍曆
vs2015+PCL1.8.1+qt5.12-----(1)
Three factors affecting personal growth








