這個效果並不難,重點是位置和比例設置, 捕捉滑鼠位置、判斷滑鼠位置區域、還有onmouseover事件、onmousemove事件、onmouseout事件 設定顯示大圖的比例,小圖上顯示的切圖比例都要弄準確點,最好是2倍啦,4倍啦。 主要注意寬度,我這裡的圖片m.jpg是1440X900的.... 複製程式碼 程式碼如下: 放大鏡效果 <BR>*{margin:0;padding:0;}<BR>#smallimg{width:360px;float:left;position:relative;border:1px solid red;}<BR>#smallimg img{ width:360px;}<BR>#bigimg{float:400px; height:400px;margin-left:40px;border:1px solid #ccc;display:none;}<BR>#ffimg{width:100px;height:100px;background:#orderf;cursor:move; position:absolute; :1px solid #666;opacity:0.5;filter:alpha(opacity=50);display:none;}<BR> <BR>var $=function(id){return typeof id=="string"?document.getElementById(id):id}<BR>var smallimg = $("smallimg");<BR>var showimg = $("showimg");//濾鏡圖片<BR>var bigimg = $("bigimg");<BR>var small_url = smallimg.getElementsByTagName(" img")[0].getAttribute("src");<BR>var show_half = maxWidth = maxHeight = 0;<BR>smallimg.onmouseover = function(){<BR> showimg.style.display = "block"; <BR> bigimg.style.display = "inline";<BR> show_half = showimg.offsetHeight/2;<BR> maxWidth = smallimg.clientWidth - showimg.offsetWidthh;<maxn; <BR> //上面兩個變數指明showimg允許活動的區域<BR>};<BR>smallimg.onmousemove = function(e){<BR> var e=window.event?window.event:e;<🎜:e;<BR> var num=bigimg.clientWidth/showimg.clientWidth;<BR> var Top = e.clientY - smallimg.offsetTop - show_half;<BR> var Left = e.clientX - ?目前移動的showimg位置計算方法是滑鼠座標- 最外面容器的座標- 盒子的寬(高)的/2 <BR> Top = Top<0?0:Top>maxHeight?maxHeight:Top;<BR> Left = Left<0?0:Left>maxWidth?maxWidth:Left;<BR> showimg.style.top = Top "px";<BR> showimg.style.left = Left "px";<BR> bigimg.style.background = "url(" small_url ") -" Left*num "px -" Top*num "px no-repeat";<BR>};<BR>smallimg.onmouseout = function(){<BR> showimg.style. display="none";<BR> bigimg.style.background ="";<BR> bigimg.style.display="none"<BR>};<BR>