图片自动按宽高比例缩小的js代码
分类:程序开发 Tags: 图片 javascript 评论:0 浏览:4311 最近更新时间:2010/7/16 13:24:00
- <script type="text/javascript">
- function setImgSize(img,width,height){
- var MaxWidth=width;//设置图片宽度界限
- var MaxHeight=height;//设置图片高度界限
- var HeightWidth=img.offsetHeight/img.offsetWidth;//设置高宽比
- var WidthHeight=img.offsetWidth/img.offsetHeight;//设置宽高比
- if(img.offsetWidth>MaxWidth){
- img.width=MaxWidth;
- img.height=MaxWidth*HeightWidth;
- }
- if(img.offsetHeight>MaxHeight){
- img.height=MaxHeight;
- img.width=MaxHeight*WidthHeight;
- }
- }
- </script>
- <img src="/pic/images4/20100716232307734.gif" border=0 onload="setImgSize(this,150,150);">
- //按比例缩小图片
- //调用方式onload="setImgSize(this,150,150)"
- var flag=false;
- function setImgSize(ImgD,Imgwidth,Imgheight){
- var image=new Image();
- image.src=ImgD.src;
- if(image.width>0 && image.height>0){
- flag=true;
- if(image.width/image.height>= 1){
- if(image.width>Imgwidth){
- ImgD.width=Imgwidth;
- ImgD.height=(image.height*Imgwidth)/image.width;
- }else{
- ImgD.width=image.width;
- ImgD.height=image.height;
- }
- }
- else{
- if(image.height>Imgheight){
- ImgD.height=Imgheight;
- ImgD.width=(image.width*Imgheight)/image.height;
- }else{
- ImgD.width=image.width;
- ImgD.height=image.height;
- }
- }
- }
- }
本文地址:/478/
-
• ASP检测网站是否能打开代码
• ASP按字段中首字母输出所有数据代码
• opencart 3.0 PayPal Payments Standard支付没有传递收货地址解决办法
• 支付宝即时到账POST按钮代码
• asp获取内容中第一张图片和全部图片代码
• ASP连接Access数据库绝对路径代码
• asp检测email地址是否有效函数
• ASP抽取数据的执行效率
• 在文章内容中随机插入网站版权文字,防止采集
• ASP过滤SQL非法字符并格式化html代码,不错的功能函数集