放大镜效果
2022/1/12 6:04:39
本文主要是介绍放大镜效果,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<!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> .container { position: relative; } .small { position: relative; width: 200px; height: 200px; border: 1px solid #ccc; /* 测试 */ margin-top: 201px; margin-left: 263px; } .small>img { width: 100%; height: 100%; } .big { display: none; position: absolute; left: 522px; top: 0; width: 400px; height: 400px; border: 1px solid #ccc; overflow: hidden; } .big>img { position: absolute; width: 800px; height: 800px; } .mask { display: none; position: absolute; left: 0; top: 0; width: 100px; height: 100px; background-color: orange; opacity: 0.5; } </style> </head> <body> <div class="container"> <div class="small"> <img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.defanli.com%2Fi3%2F1637289231%2FO1CN01Ldp9fc2I3qkCMF8H5_%21%211637289231.jpg_q90.jpg&refer=http%3A%2F%2Fimg.defanli.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1644506916&t=6e9b0c11f89b561cccbfbeb74b76ae89" alt=""> <div class="mask"></div> </div> <div class="big"> <img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.defanli.com%2Fi3%2F1637289231%2FO1CN01Ldp9fc2I3qkCMF8H5_%21%211637289231.jpg_q90.jpg&refer=http%3A%2F%2Fimg.defanli.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1644506916&t=6e9b0c11f89b561cccbfbeb74b76ae89" alt=""> </div> </div> <script src="./jquery-1.12.4.js"></script> <script> $(function () { const small = $('.small') const mask = $('.mask') const big = $('.big') small.hover(function () { mask.css("display", "block"); big.css("display", "block"); }, function () { mask.css("display", "none"); big.css("display", "none"); }) small.on("mousemove", function (ev) { let x = ev.pageX - (small.offset().left - small.scrollLeft()) - mask.width() / 2 let y = ev.pageY - (small.offset().top - small.scrollTop()) - mask.height() / 2 if (x < 0) { x = 0; } if (y < 0) { y = 0; } if (x > small.width() - mask.width()) { x = small.width() - mask.width(); } if (y > small.height() - mask.height()) { y = small.height() - mask.height(); } mask.css({ left: x, top: y }); // 放大倍数 rateX = 4; $('.big>img').css({ left: -rateX * x, top: -rateX * y }); }) }) </script> </body> </html>
这篇关于放大镜效果的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-102025 蛇年,J 人直播带货内容审核团队必备的办公软件有哪 6 款?
- 2025-01-10高效运营背后的支柱:文档管理优化指南
- 2025-01-10年末压力山大?试试优化你的文档管理
- 2025-01-10跨部门协作中的进度追踪重要性解析
- 2025-01-10总结 JavaScript 中的变体函数调用方式
- 2025-01-10HR团队如何通过数据驱动提升管理效率?6个策略
- 2025-01-10WBS实战指南:如何一步步构建高效项目管理框架?
- 2025-01-10实现精准执行:团队协作新方法
- 2025-01-10如何使用工具提升活动策划团队的工作效率?几个必备工具推荐
- 2025-01-10WiX 标签使用介绍:打造专业安装程序的利器