- function makesmallpic(obj,w,h){
- var srcImage = new Image();
- srcImage.src=obj.src;
- var srcW=srcImage.width;
- var srcH=srcImage.height;
- if(srcW>srcH){
- if(srcW>w){
- obj.width=newW=w;
- obj.height=newH=(w/srcW)*srcH;
- }else{
- obj.width=newW=srcW;
- obj.height=newH=srcH;
- }
- }else{
- if(srcH>h){
- obj.height=newH=h;
- obj.width=newW=(h/srcH)*srcW;
- }else{
- obj.width=newW=srcW;
- obj.height=newH=srcH;
- }
- }
- if(newW>w){
- obj.width=w;
- obj.height=newH*(w/newW);
- }else if(newH>h){
- obj.height=h;
- obj.width=newW*(h/newH);
- }
- }
- 本文来自爱秋天电脑教程网 http://www.loveqiutian.cn, 本文地址:http://www.loveqiutian.cn/bencandy.php?aid=61344
js判断图片宽度并限制宽度和高度的javascript代码
最新推荐文章于 2022-05-18 16:53:02 发布