網路上一大堆限制多,文件也難看懂,而且麻煩~自己寫了個。大笑演算法: 第一步: 放大圖片的位置=滑鼠所在的容器的寬或高除以容器本身的高度和寬度,求滑鼠在容器中移動的百分比第二個: 得到百分比之後x=-(x百分比*圖片的寬度-顯示容器的寬度/2); y=-(y百分比*圖片的高度-顯示容器的高度/2); 兩個參數,x和y ,就是大圖的位置了,後面加了個顯示容器的大小/2 是為了確保圖片顯示在中間。 效果圖: 代碼: 複製代碼 代碼如下: 商品信息 <br><br>html,body,img,a,div{ <BR>margin: 0px; <BR>padding: 0px; <BR>border: 0px; <BR>font: 12px/150% Arial,Verdana,"宋体"; <BR>color: rgb(102, 102, 102); <BR>} <br><br>div:after { <BR>clear: both; <BR>content: '.'; <BR>height:0; <BR>visibility: hidden; <BR>diplay: block; <BR>} <br><br>div { <BR>zoom: 1; <BR>} <BR>.main-body{ <BR>text-align: center; <BR>padding: 15px; <BR>} <BR>.head-box{ <BR>height: 400px; <BR>border: #CCC 1px solid; <BR>} <BR>.head-box-left{ <BR>width: 300px; <BR>height: 390px; <BR>/*border: #CCC 1px solid;*/ <BR>float: left; <BR>padding: 3px; <BR>position: relative; <BR>} <BR>.head-box-right{ <BR>width: 500px; <BR>height: 390px; <BR>border: #CCC 1px solid; <BR>float: left; <BR>margin-left: 10px; <BR>} <BR>.goods-max-img{ <BR>width: 300px; <BR>height: 300px; <BR>display:block; <BR>border: #CCC 1px solid; <BR>position: relative; <BR>cursor: move; <BR>} <BR>.goods-img-list{ <BR>width: 300px; <BR>height: 80px; <br><br>margin-top: 10px; <BR>} <br><br>.goods-change{ <BR>display: block; <BR>float: left; <BR>width: 17px; <BR>height: 54px; <BR>background: url("../web/imgs/goods-change-btn.png"); <BR>} <BR>.change-prev{ <BR>margin-right: 5px; <BR>margin-left: 2px; <BR>} <BR>.change-prev:HOVER{ <BR>background-position: -34px 0px; <BR>} <BR>.change-next{ <BR>margin-left: 5px; <BR>background-position: -17px 0px; <BR>} <BR>.change-next:HOVER{ <BR>margin-left: 5px; <BR>background-position: -51px 0px; <BR>} <br><br>.goods-img-list-box{ <BR>width: 250px; <BR>height: 54px; <BR>/*border:1px #CCC solid;*/ <BR>border: 0px 1px; <BR>float: left; <BR>position: relative; <BR>overflow: hidden; <BR>} <BR>.goods-img-list-box ul{ <BR>margin: 0px; <BR>padding: 0px; <BR>position: absolute; <BR>top: 1px; <BR>left: 0px; <BR>width: 500px; <BR>} <BR>.goods-img-list-box ul li{ <BR>display: block; <BR>float: left; <BR>width: 50px; <BR>height: 50px; <BR>border: #CCC 1px solid; <BR>margin-left: 3px; <BR>} <BR>.goods-img-list-box ul li a{ <BR>display: block; <BR>width: 100%; <BR>height: 100%; <BR>text-decoration: none; <BR>} <BR>.preview-box{ <BR>position: absolute; <BR>top: 0px; <BR>width: 500px; <BR>height: 500px; <BR>background-color: white; <BR>border: #CCC 1px solid; <BR>left: 310px; <BR>display: none; <BR>overflow: hidden; <BR>} <br><br> <br><br>$(function(){ <br><br>$(".goods-max-img").mousemove(function(event){ <BR>$(".preview-box").show(); <BR>//计算百分比 <BR>var x=event.screenX; <BR>var y=event.screenY; <BR>x-=$(this).offset().left; <BR>y=y-$(this).offset().top-65; <BR>//得出比例 <BR>x=(x/300).toFixed(2); <BR>y=(y/300).toFixed(2); <br><br>//250 容器的大小/2 <BR>x=-($("#preview-img").width()*x-250); <BR>y=-($("#preview-img").height()*y-250); <br><br>$("#preview-img").css('top',y+'px'); <BR>$("#preview-img").css('left',x+'px'); <BR>document.title=x+","+y; <BR>}); <br><br>$(".goods-max-img").mouseout(function(){ <BR>$(".preview-box").hide(); <BR>}); <br><br>}); <br><br> ; ; 8 7 a> 6 5 3 3 2 身體>