js 图片缩放(按比例)控制代码


Posted in Javascript onMay 27, 2009

缩放代码:

缩放代码: 
<script type="text/javascript"> 
//图片按比例缩放 
var flag = false; 
function DrawImage(ImgD, iwidth, iheight) { 
//参数(图片,允许的宽度,允许的高度) 
var image = new Image(); 
image.src = ImgD.src; 
if (image.width > 0 && image.height > 0) { 
flag = true; 
if (image.width / image.height >= iwidth / iheight) { 
if (image.width > iwidth) { 
ImgD.width = iwidth; 
ImgD.height = (image.height * iwidth) / image.width; 
} else { 
ImgD.width = image.width; 
ImgD.height = image.height; 
} 
ImgD.alt = image.width + "×" + image.height; 
} 
else { 
if (image.height > iheight) { 
ImgD.height = iheight; 
ImgD.width = (image.width * iheight) / image.height; 
} else { 
ImgD.width = image.width; 
ImgD.height = image.height; 
} 
ImgD.alt = image.width + "×" + image.height; 
} 
} 
} 
</script> 
页面代码: 
<img onload="javascript:DrawImage(this,89,63)" src="https://3water.com/images/logo.gif" width="89" height="63" border="0" /> 
觉得不错的发个言!

页面代码:
1. <img onload="javascript:DrawImage(this,89,63)" src="http://www.baidu.com/img/baidu_logo.gif" width="89" height="63" border="0" />
觉得不错的发个言!
Javascript 相关文章推荐
原型方法的不同写法居然会影响调试的解决方法
Mar 08 Javascript
js判断变量是否未定义的代码
Mar 28 Javascript
window.location.href = window.location.href 跳转无反应 a超链接onclick事件写法
Aug 21 Javascript
JavaScript判断密码强度(自写代码)
Sep 06 Javascript
Window.Open如何在同一个标签页打开
Jun 20 Javascript
基于JavaScript实现百叶窗动画效果不只单纯flas可以实现
Feb 29 Javascript
jQuery页面元素动态添加后绑定事件丢失方法,非 live
Jun 16 Javascript
AngularJS中的缓存使用
Jan 11 Javascript
javascript表单正则应用
Feb 04 Javascript
JS简单获取当前年月日星期的方法示例
Feb 07 Javascript
如何实现js拖拽效果及原理解析
May 08 Javascript
ES6字符串的扩展实例
Dec 21 Javascript
图片上传即时显示缩略图的js代码
May 27 #Javascript
JavaScript 闭包深入理解(closure)
May 27 #Javascript
jQuery 剧场版 你必须知道的javascript
May 27 #Javascript
javascript 日期时间函数(经典+完善+实用)
May 27 #Javascript
jquery cookie插件代码类
May 26 #Javascript
判断脚本加载是否完成的方法
May 26 #Javascript
javascript 复杂的嵌套环境中输出单引号和双引号
May 26 #Javascript
You might like
浅谈PHP 闭包特性在实际应用中的问题
2009/10/30 PHP
PHP比较运算符的详细介绍
2015/09/29 PHP
详解WordPress中用于合成数组的wp_parse_args()函数
2015/12/18 PHP
比较简单实用的使用正则三种版本的js去空格处理方法
2007/11/18 Javascript
asp 取文本框名称代码
2008/12/02 Javascript
js href的用法
2010/05/13 Javascript
JQuery切换显示的效果实例代码
2013/02/27 Javascript
jquery解析JSON数据示例代码
2014/03/17 Javascript
javascript数组遍历for与for in区别详解
2014/12/04 Javascript
js实现(全选)多选按钮的方法【附实例】
2016/03/30 Javascript
JS Array创建及concat()split()slice()的使用方法
2016/06/03 Javascript
JS实现的自定义水平滚动字体插件完整实例
2016/06/17 Javascript
JS实现的简单表单验证功能完整实例
2017/10/14 Javascript
微信小程序实现倒计时功能
2020/11/19 Javascript
Python制作豆瓣图片的爬虫
2017/12/28 Python
Django错误:TypeError at / 'bool' object is not callable解决
2019/08/16 Python
PyTorch 普通卷积和空洞卷积实例
2020/01/07 Python
python super函数使用方法详解
2020/02/14 Python
解决paramiko执行命令超时的问题
2020/04/16 Python
Python3之乱码\xe6\x97\xa0\xe6\xb3\x95处理方式
2020/05/11 Python
基于Python3读写INI配置文件过程解析
2020/07/23 Python
python实现批处理文件
2020/07/28 Python
Python数据可视化常用4大绘图库原理详解
2020/10/23 Python
Python plt 利用subplot 实现在一张画布同时画多张图
2021/02/26 Python
德国综合购物网站:OTTO
2018/11/13 全球购物
Shein英国:女性时尚网上商店
2019/04/10 全球购物
俄罗斯品牌服装和鞋子的在线商店:KUPIVIP
2019/10/27 全球购物
Talbots官网:美国成熟女装品牌
2019/11/15 全球购物
什么是ARP(Address Resolution Protocol)地址解析协议
2013/10/31 面试题
金融专业应届生求职信
2013/11/02 职场文书
开展党的群众路线教育实践活动方案
2014/02/05 职场文书
股东授权委托书
2014/10/15 职场文书
介绍信如何写
2015/01/31 职场文书
小学作文指导之如何写人?
2019/07/08 职场文书
nginx proxy_cache 缓存配置详解
2021/03/31 Servers
一次SQL如何查重及去重的实战记录
2022/03/13 MySQL