当前位置:网站首页>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>
边栏推荐
- win32
- Markov decision process (MDP): Blackjack problem (mc-es)
- socket demo01
- 微博评论的高性能高可用计算架构
- 基于邻接表的广度优先遍历
- It's better to finish one than start thousands of times (reprinted from Douban)
- ARM流水线如何提高代码执行效率
- Prompt to update to the latest debug version during vscode debugging
- Redis-SDS
- 论文阅读 Exploring Temporal Information for Dynamic Network Embedding
猜你喜欢
奶牛排序问题
Implementation of image binary morphological filtering based on FPGA -- Corrosion swelling
shell学习记录(四)
为 ServiceCollection 实现装饰器模式
表达式的动态解析和计算,Flee用起来真香
SDRAM Controller - add read / write FIFO
Chrome浏览器开发者工具使用
One minute to understand the difference between synchronous, asynchronous, blocking and non blocking
Blazor University (33)表单 —— EditContext、FieldIdentifiers
Getting to know OpenGL
随机推荐
深度好文:什么是超网 Supernetting?
奶牛排序问题
Connectez Le projecteur
SQL column value to row value (unpivot)
Multi type study of Worthington collagen protease
leetcode 300. Longest Increasing Subsequence 最长递增子序列 (中等)
购买了fastadmin小程序助手但是问题工单中无法发布工单
Redis-SDS
FPGA实现图像二值形态学滤波——腐蚀膨胀
Tab switch
哪个证券公司手机股票开户更好更安全?
Ndk20b ffmpeg4.2.2 compilation and integration
Shell curl execution script, with passed parameters and user-defined parameters
vs2015+PCL1.8.1+qt5.12-----(1)
Scala 基础 (二):变量和数据类型
A solution to cross domain problems
heaven and hell's moving
Sqlyog shortcut keys
Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming!
SDRAM控制器——仲裁模块的实现