网上一大堆限制多,文档也难看懂,而且麻烦~自己写了个。大笑 算法: 第一步: 放大图片的位置=鼠标所在的容器的宽或者高除以容器自身的高度和宽度,求出鼠标在容器中移动的百分比 第二部: 得到百分比之后 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 6 5 3 3 2