商城放大镜以及图片切换功能

阅读: 评论:0

商城放大镜以及图片切换功能

商城放大镜以及图片切换功能

一、效果图

1.开始效果图

2.放大镜效果图

 3.图片切换功能(鼠标移入下方相应图片,上面以及放大图片相继改变)

 二、HTMl代码

        <div class="box1"><div id="smallbox" class="small"><img id="smallImg" src="./img/da1.jpg"/><div id="mask" class="mask"></div></div><div class="bottom"><div id="bottomImg1"><img src="./img/xiao1.webp" alt=""></div><div id="bottomImg2"><img src="./img/xiao2.webp" alt=""></div><div id="bottomImg3"><img src="./img/xiao3.webp" alt=""></div></div></div><div id="bigbox" class="big"><img id="bigImg" src="./img/da1.jpg"/></div>

三、CSS代码

			*{margin: 0px;padding:  0px;}#smallbox{width: 300px;height: 300px;position: relative;border: 1px solid gray;}#smallbox img{width: 100%;height: 100%;}.mask{width: 100px;height: 100px;background-color: black;opacity: 0.3;position: absolute;top: 0;left: 0;display: none;cursor: move;}.big{width: 400px;height: 400px;overflow: hidden;position: relative;border: 1px solid gray;margin-left: 20px;display: none;z-index: 10;}.big img{width: 800px;height: 800px;position: absolute;top: 0;left: 0;}.small,.big{float: left;}.bottom{width: 300px;float: left;}.bottom div {width: 90px;height: 90px;background-color: blue ;margin-right: 10px;float: left;}.bottom img{width: 100%;height: 100%;}.box1{width: 300px;height: 300px;float: left;}

四、JavaScript代码

// 获取各个元素var smallBox = ElementById("smallbox");var mask = ElementById("mask");var bigbox = ElementById("bigbox");var bigImg = ElementById("bigImg");var smallImg = ElementById("smallImg")var bottomImg1 &#ElementById("bottomImg1");var bottomImg2 &#ElementById("bottomImg2");var bottomImg3 &#ElementById("bottomImg3");//移入鼠标,显示图片和放大图片改为的模块一的图片useover = function(){smallImg.src = "./img/da1.jpg";bigImg.src = "./img/da1.jpg"}//移入鼠标,显示图片和放大图片改为的模块一的图片useover = function(){smallImg.src = "./img/da2.jpg";bigImg.src = "./img/da2.jpg"}//移入鼠标,显示图片和放大图片改为的模块一的图片useover = function(){smallImg.src = "./img/da3.jpg";bigImg.src = "./img/da3.jpg"}// 移入鼠标,遮罩层和放大图片显示useover = function(){mask.style.display = "block";bigbox.style.display = "block";}// 移出鼠标,遮罩层和放大图片隐藏useout = function(){mask.style.display = "none";bigbox.style.display = "none";}// 进行放大镜设置usemove = function(e){var x = e.clientX - smallBox.offsetLeft -mask.offsetWidth/2;var y = e.clientY - smallBox.offsetTop -mask.offsetHeight/2;if (x<0){x=0;}if(x>(smallBox.offsetWidth - mask.offsetWidth)){x=smallBox.offsetWidth - mask.offsetWidth;}if(y<0){y=0;}if(y>(smallBox.offsetHeight - mask.offsetHeight)){y=smallBox.offsetHeight - mask.offsetHeight;}mask.style.left = x +'px';p = y +'px';bigImg.style.left = -2*x+'px';p = -2*y+'px';}

提示:

相关图片信息请自行修改

本文发布于:2024-01-29 04:38:35,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170647431812754.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:放大镜   功能   商城   图片
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23