会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
emu
博客园
首页
新随笔
联系
订阅
管理
用javascript放大图片局部
<
html
>
<
head
>
<
title
>
emu
</
title
>
</
head
>
<
body
>
<
BR
>
原图:
<
BR
>
<
img
src
="http://img.pconline.com.cn/images/photo2/839980/1118509777696.JPG"
onmousemove
="zoom()"
id
=srcImg>
<BR
>
局部放大图:
<
BR
>
<
div
style
="overflow:hidden"
><
img
id
=zoomImg></div>
<SCRIPT LANGUAGE
="JavaScript"
>
<!--
zoomImg.src = srcImg.src;
srcImg.height = srcImg.height/2;
var zoomRate = 5;
zoomImg.height = srcImg.height*zoomRate;
zoomImg.parentNode.style.width = srcImg.width;
zoomImg.parentNode.style.height = srcImg.height;
function zoom(){
var elm = event.srcElement;
h = elm.offsetHeight/zoomRate/2;
w = elm.offsetWidth/zoomRate/2;
var x = event.x-elm.offsetLeft;
x=x<(elm.offsetWidth-w)?x<w?w:x:elm.offsetWidth-w;
zoomImg.style.marginLeft=(w-x)*zoomRate;
var y = event.y-elm.offsetTop;
y=y<(elm.offsetHeight-h)?y<h?h:y:elm.offsetHeight-h;
zoomImg.style.marginTop=(h-y)*zoomRate;
}
//
-->
</
SCRIPT
>
</
body
>
</
html
>
posted @
2005-07-13 18:01
emu
阅读(
151
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告