<img src="http://files.jb51.net/upload/20071130224657571.jpg" border="0" alt="그림돋보기 효과 code_image 특수효과" > <br><div class="htmlarea"> <textarea id="runcode37699"> <!-- *** 斩梦人.天天 [原创]分享 *** QQ:22062019 Email:takuma888@126.com *** *** 欢迎大家引用和改进,但希望大家能珍惜作者的劳动,最好能注明出处. *** 由于浏览器兼容性的问题,在FF和OP下表现不是很理想,没能完善,还请见谅. //--> <style type="text/css"> <!-- *{padding:0;margin:0} img{display:block;} #smallbox{border:1px #c33 solid;float:left;width:0;height:0;overflow:hidden} #bigbox{border:1px #c33 solid;width:0px;height:0px;float:left;background:url('/upload/20071130224657571.jpg') no-repeat;} #view{border:1px #ddd solid;width:0px;height:0px;position:absolute} .head{text-align:center;line-height:40px;font:bold 16px/40px;color:red} //--> </style> <div class="head"> </div>사진 확대 효과<div id="smallbox"> <img id="smallpic" src="http://files.jb51.net/upload/20071130224657571.jpg" border="0" onmousemove="move(event)" alt="그림돋보기 효과 code_image 특수효과" > </div> <div id="bigbox"> </div> <div id="view"> </div></textarea> <br><input onclick="runEx('runcode37699')" type="button" value="运行代码"><input onclick="doCopy('runcode37699')" type="button" value="复制代码"> <input onclick="doSave(runcode37699)" type="button" value="保存代码"> <a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">[Ctrl A 모두 선택 참고: </a>외부 J를 도입해야 하는 경우 실행하려면 새로 고쳐야 합니다 </div>]<script language="JavaScript"> <!-- var srcX = 1024; //原图长宽 var srcY = 768; var bigX = 500; //原比例预览大小,可以设置成任意大小 var bigY = 300; var smallX = 256; //缩略图大小,要与原大小成比例 var smallY = 192; var viewX = bigX / srcX * smallX; //预览范围 var viewY = bigY / srcY * smallY; var bl = srcX / smallX;//缩小比例 var border = 8; //边框 window.onload=function (){ bigbox.style.borderWidth=border; bigbox.style.width=bigX+border*2; bigbox.style.height=bigY+border*2; smallpic.width=smallX; smallpic.height=smallY; view.style.width=viewX; view.style.height=viewY; smallbox.style.borderWidth=border; if (window.event){ smallbox.style.width=smallpic.offsetWidth+border*2; smallbox.style.height=smallpic.offsetHeight+border*2; }else{ smallbox.style.width=smallpic.offsetWidth; smallbox.style.height=smallpic.offsetHeight; } move(event); } function move(e){ var e = window.event?window.event:e; var iebug = 0; if (window.event){ var vX = e.offsetX - viewX/2; var vY = e.offsetY - viewY/2; }else{ var vX = e.pageX - viewX/2 - smallbox.offsetLeft - border; var vY = e.pageY - viewY/2 - smallbox.offsetTop - border; iebug = 2; } if (vX < 0) vX = 0; if (vY < 0) vY = 0; if (vX > smallX - viewX - iebug) vX = smallX - viewX - iebug; if (vY > smallY - viewY - iebug) vY = smallY - viewY - iebug; view.style.left = vX + smallbox.offsetLeft + border; view.style.top = vY + smallbox.offsetTop + border; bigbox.style.backgroundPosition= - vX * bl + " " + -vY * bl; } //--> </script>