js控制图片大小的相关代码

1、用鼠标拖动来改变大小

<script language="javascript">
    function resizeimage(evt,obj){
    newx=evt.x
    newy=evt.y
    obj.width=newx
    obj.height=newy
}
</script>
<img src="7say.gif" ondrag="resizeimage(event,this)">

2、用鼠标滚动控制图片大小

<img src="7say.gif" onmouseenter="focus();" onmouseout="blur();" onmousewheel="width+=(window.event.wheeldelta==120)?-5:+5;">

3、图片标签里用代码控制大小

<img border="0" src="[!--picurl--]" onload="if(this.width>screen.width-500)this.style.width=screen.width-500;">

经测试这里需要修改一下,不然刷新网页时图片会显示原始大小。

<img border="0" src="[!--picurl--]" onload="if(this.width>screen.width-500)this.resized=true;this.style.width=screen.width-500;">

4、css控制图片大小
1. css2直接实现: img{max-width: 500px;} (ie暂不支持)
2. expression实现: img{width:expression(width>500?"500px":width);} (ie only)
3. 使用js. 方法: 用 document.getelementsbytagname("img") 的方法取得全部img元素 遍历img元素 判断其宽度并做相应操作