国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

用JS實(shí)現(xiàn)購物網(wǎng)站商品放大鏡效果

2020-07-27 21:26:32
字體:
供稿:網(wǎng)友

放大鏡效果就是把鼠標(biāo)移到圖片上的時候,旁邊會有另外一張大的圖片展示,放大鏡效果,那這樣的效果怎樣實(shí)現(xiàn)的呢,我把代碼發(fā)給大家,請大家參考。

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>放大鏡</title> <style> *{margin:0;padding: 0;} #warp{width: 1184px;height:500px;margin:50px auto 0;background-color: #ccc;overflow: hidden;padding: 10px;position: relative;} #warp #minbox{width: 350px;height: 350px;float: left;position: relative;} #maxbox{width: 400px;height: 400px;position: absolute;left: 380px;overflow: hidden;display: none;} #maxbox img{width: 800px;height: 800px;position: absolute;} #con{float: left;margin-left: 20px;} #meng{width: 175px;height: 175px;position: absolute;background-color:yellow;opacity:0.4;filter:alpha(opacity=40);left: 0;top: 0;display: none;} </style></head><body> <div id="warp"> <div id="minbox">  <img src="images/min.jpg" alt="">  <p id="meng"></p> </div> <div id="maxbox">  <img src="images/max.jpg" alt=""> </div> <div id="con">  <img src="images/msg.png" alt=""> </div> </div> <script> var minbox=document.getElementById('minbox'); var meng=document.getElementById('meng'); var maxbox=document.getElementById('maxbox'); var maximg=maxbox.getElementsByTagName('img')[0]; var minimg=minbox.getElementsByTagName('img')[0]; function offsetTL(obj){  var ofL=0,ofT=0;  while(obj){  ofL+=obj.offsetLeft+obj.clientLeft;  ofT+=obj.offsetTop+obj.clientTop;  obj=obj.offsetParent;  }  return{left:ofL,top:ofT}; } minbox.onmousemove=function(e){  var e=e||window.event;  meng.style.display='block';  maxbox.style.display='block';  var niubi1=e.clientX-offsetTL(minbox).left-meng.clientWidth/2;//蒙板的X坐標(biāo)  var niubi2=e.clientY-offsetTL(minbox).top-meng.clientHeight/2;//蒙板的Y坐標(biāo)  var bili=maximg.clientWidth/minimg.clientWidth;  if (niubi1<=0) {  niubi1=0;  }else if (niubi1>=minbox.clientWidth-meng.clientWidth) {  niubi1=minbox.clientWidth-meng.clientWidth;  }  if (niubi2<=0) {  niubi2=0;  }else if (niubi2>=minbox.clientHeight-meng.clientHeight) {  niubi2=minbox.clientHeight-meng.clientHeight;  }  console.log(niubi1);  console.log(niubi2);  meng.style.left=niubi1+'px';  meng.style.top=niubi2+'px';  maximg.style.left=-parseInt(meng.style.left)*bili+'px';  maximg.style.top=-parseInt(meng.style.top)*bili+'px'; } minbox.onmouseout=function(){  meng.style.display='none';  maxbox.style.display='none'; } </script></body></html>

效果如下:

希望本文所述對大家javascript程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 万州区| 太保市| 南涧| 清远市| 龙海市| 临夏市| 太原市| 松潘县| 秦皇岛市| 西峡县| 华坪县| 岗巴县| 博乐市| 黔西| 博乐市| 扶绥县| 松潘县| 阿城市| 凉山| 当涂县| 阳泉市| 孝义市| 托克逊县| 张北县| 洛浦县| 怀宁县| 英山县| 隆林| 徐州市| 来凤县| 开阳县| 视频| 清水河县| 贵溪市| 建始县| 河津市| 九龙城区| 盐边县| 绥棱县| 云龙县| 湖南省|