当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 网页里控制图片大小的相关代码

Javascript
JavaScript 渐变效果页面图片控制
JavaScript blog式日历控件新算法
Javascript 读后台cookie代码
js 弹簧效果代码
JavaScript滑移效果代码
javascript字符串拆分成单个字符相加和不超过10,求最终值
Prototype中dom对象方法汇总
Jquery与Prototype混合用法对比
javascript下IE与FF兼容函数收集
突破winxp sp2/win2003 sp2超强弹窗代码
js点击出现场层层外点击层消失的代码
Javascript模拟scroll滚动效果脚本
javascript各种复制代码收集
javascript的trim,ltrim,rtrim自定义函数
仿3721首页模块拖曳移动效果js代码[可拖曳层移动层]
Javascript拖拽系列文章1之offsetParent属性
Discuz! 6.1_jQuery兼容问题
js日历控件(可精确到分钟)
javascript DOM实用学习资料
javascript实现的树型下拉框改进版

Javascript 中的 网页里控制图片大小的相关代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 314 ::
收藏到网摘: n/a

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元素 判断其宽度并做相应操作