前端JS电商放大镜效果
2018-06-24 00:02:25来源:未知 阅读 ()
前端JS电商放大镜效果:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>26-电商放大镜</title> <style type="text/css"> *{ padding: 0; margin: 0; } #left{ padding: 0; margin: 0; width: 400px; height: 400px; border: 2px solid blue; background: url(http://chuantu.biz/t6/17/1503469475x2063891122.jpg) no-repeat; float: left; cursor: crosshair; position: relative; box-sizing: border-box; } #box{ width: 200px; height: 200px; background: white; opacity: 0.6; position: absolute; top: 0; left: 0; display: none; box-sizing: border-box; } #cover{ width: 400px; height: 400px; background: red; position: absolute; left: 0; top: 0; opacity: 0; box-sizing: border-box; } #right{ width: 400px; height: 400px; border: 2px solid black; overflow: hidden; position: relative; display: none; box-sizing: border-box; } #rpic{ position: absolute; } </style> <script type="text/javascript"> window.onload = function(){ var left = document.getElementById("left"); var right = document.getElementById("right"); var rpic = document.getElementById("rpic"); var box = document.getElementById("box"); var cover = document.getElementById("cover"); // 给左侧加鼠标移动事件 cover.onmousemove = function(){ //获得事件对象 var ev = window.event; var mouse_left = ev.offsetX || ev.layerX; var mouse_top = ev.offsetY || ev.layerY; // document.title = mouse_left + '|' + mouse_top; //计算色块的位置 var box_left = mouse_left - 100; var box_top = mouse_top - 100; // 判断是否超出 if (box_left < 0) { box_left = 0; } if (box_left > 200) { box_left = 200; } if (box_top < 0) { box_top = 0; } if (box_top > 200) { box_top = 200; } // 让色块移动 box.style.left = box_left + 'px'; box.style.top = box_top + 'px'; //计算右侧图片位置 var rpic_left = box_left*-2; var rpic_top = box_top*-2; // 让右侧移动 rpic.style.left = rpic_left + 'px'; rpic.style.top = rpic_top + 'px'; } //给左侧加鼠标移入事件 cover.onmouseover = function(){ // 让左侧色块和右侧隐藏 box.style.display = 'block'; right.style.display = 'block'; } // 给左侧加鼠标移出事件 cover.onmouseout = function(){ // 让左侧色块和右侧隐藏 box.style.display = 'none'; right.style.display = 'none'; } } </script> </head> <body> <div id="left"> <div id="box"></div> <div id="cover"></div> </div> <div id="right"> <img src="http://chuantu.biz/t6/17/1503469419x2063891122.jpg" id="rpic"> </div> </body> </html>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- js调用刷新界面的几种方式 2020-03-05
- jQuery实现的放大镜效果示例 2020-02-21
- 高性能JavaScript循环语句和条件语句 2020-02-21
- Javascript实现前端简单的路由实例 2019-12-17
- 带你了解JavaScript 2019-10-29
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash