JS实现电商放大镜效果
网络编程 2021-07-04 18:33www.168986.cn编程入门
这篇文章主要为大家详细介绍了JS实现电商放大镜效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
前端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./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; : 0; left: 0; display: none; box-sizing: border-box; } #cover{ width: 400px; height: 400px; background: red; position: absolute; left: 0; : 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_ = ev.offsetY || ev.layerY; // document.title = mouse_left + '|' + mouse_; //计算色块的位置 var box_left = mouse_left - 100; var box_ = mouse_ - 100; // 判断是否超出 if (box_left < 0) { box_left = 0; } if (box_left > 200) { box_left = 200; } if (box_ < 0) { box_ = 0; } if (box_ > 200) { box_ = 200; } // 让色块移动 box.style.left = box_left + 'px'; box.style. = box_ + 'px'; //计算右侧图片位置 var rpic_left = box_left*-2; var rpic_ = box_*-2; // 让右侧移动 rpic.style.left = rpic_left + 'px'; rpic.style. = rpic_ + '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./t6/17/1503469419x2063891122.jpg" id="rpic"> </div> </body> </html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程