喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 帮助

RSS 订阅当前论坛  

喜悦证交所已经关闭

上一主题 下一主题
     
标题: 求教js控制图片问题  
 
cxrich
高级会员
Rank: 4
老会员



UID 15248
精华 0
积分 507
帖子 538
金钱 507 喜悦币
威望 0
人脉 0
阅读权限 50
注册 2002-7-14
来自 北京
状态 离线
[广告]: q m
求教js控制图片问题

我要在页面上显示图片,但是图片长宽要不能超过一个限制,超过后按比例缩小,图片显示的长宽比例和原图片一样,谁知道JS如何做?
2003-11-2 01:25 PM#1
查看资料  访问主页  Blog  发短消息  QQ  顶部
 
星之海洋2 (星之海洋2)
高级会员
Rank: 4
版主



UID 17773
精华 0
积分 904
帖子 902
金钱 904 喜悦币
威望 0
人脉 0
阅读权限 50
注册 2002-11-16
来自 hy.zj.China
状态 离线
[推荐阅读] 十年穿衣术--男人篇
<SCRIPT LANGUAGE="JavaScript">
scaleImges(img,300,150);
function scaleImges(obj,w,h) {
with(obj) {
    if(offsetWidth>w||offsetHeight>h) {
                style.width=offsetWidth/2;
                style.height=offsetHeight/2;
        }
}
}
</SCRIPT>
<IMG SRC="xxx.gif" id="img">
2003-11-3 12:44 AM#2
查看资料  访问主页  发短消息  QQ  顶部
 
cxrich
高级会员
Rank: 4
老会员



UID 15248
精华 0
积分 507
帖子 538
金钱 507 喜悦币
威望 0
人脉 0
阅读权限 50
注册 2002-7-14
来自 北京
状态 离线
[推荐阅读] 有没有这样的函数啊????在线等...ing
还是不对呀
2003-11-4 11:33 AM#3
查看资料  访问主页  Blog  发短消息  QQ  顶部
 
Ken.Chou (Ken.Chou)
金牌会员
Rank: 6Rank: 6
资深会员



UID 17290
精华 1
积分 1048
帖子 1027
金钱 1038 喜悦币
威望 10
人脉 0
阅读权限 70
注册 2002-10-26
来自 中国
状态 离线
[推荐阅读] 好奇怪!!!!!!!!!!!


<?php
<script language="JavaScript" type="text/javascript">
/** 自动调整图片尺寸
 ** Ken.Chou<kenchou77@hotmail.com>
 ** 20030908
 */
imageMaxWidth 150;    //限制图片最大宽度
imageMaxHeight 150;    //限制图片最大高度

function DrawImage(srcalt)
{
    var 
image = new Image();
    
image.src src;
    if (
image.width && image.height 0) {
        
//如果宽度大于高度
        
if (image.width/image.height >= imageMaxWidth/imageMaxHeight) {
            if (
image.width >= imageMaxWidth) {
                
width imageMaxWidth;
                
height imageMaxWidth image.height image.width//高=高*比率; 比率=最大宽度/宽度
            
}else {
                
//不变
                
width image.width;
                
height image.height;
            }
        }else {
        
//宽度小于高度
            
if(image.height>80){  
                
width image.width imageMaxHeight image.height;     
                
height imageMaxHeight;
            }else{
                
width image.width;  
                
height image.height;
            }
        }
        
document.write('<img src="' src '" width=' width 'height=' height ' border=0 alt="' alt +'">');
    }
}
</script>
?>
2003-11-4 01:38 PM#4
查看资料  发短消息  QQ  顶部
 
Ken.Chou (Ken.Chou)
金牌会员
Rank: 6Rank: 6
资深会员



UID 17290
精华 1
积分 1048
帖子 1027
金钱 1038 喜悦币
威望 10
人脉 0
阅读权限 70
注册 2002-10-26
来自 中国
状态 离线
[推荐阅读] 怎样才能在 switch 里用到循环语句控制显示case??
论坛的代码[php][/php]格式有BUG (+_+)

<script language="JavaScript" type="text/javascript">
/** 自动调整图片尺寸
** Ken.Chou<kenchou77@hotmail.com>
** 20030908
*/
imageMaxWidth = 150;        //限制图片最大宽度
imageMaxHeight = 150;        //限制图片最大高度

function DrawImage(src, alt)
{
        var image = new Image();
        image.src = src;
        if (image.width > 0 && image.height > 0) {
                //如果宽度大于高度
                if (image.width/image.height >= imageMaxWidth/imageMaxHeight) {
                        if (image.width >= imageMaxWidth) {
                                width = imageMaxWidth;
                                height = imageMaxWidth * image.height / image.width; //高=高*比率; 比率=最大宽度/宽度
                        }else {
                                //不变
                                width = image.width;
                                height = image.height;
                        }
                }else {
                //宽度小于高度
                        if(image.height>80){  
                                width = image.width * imageMaxHeight / image.height;     
                                height = imageMaxHeight;
                        }else{
                                width = image.width;  
                                height = image.height;
                        }
                }
                document.write('<img src="' + src + '" width=' + width + 'height=' + height + ' border=0 alt="' + alt +'">');
        }
}
</script>
2003-11-4 01:42 PM#5
查看资料  发短消息  QQ  顶部
 
ljcao (ljcao)
注册会员
Rank: 2
中级会员



UID 16147
精华 2
积分 185
帖子 145
金钱 165 喜悦币
威望 20
人脉 0
阅读权限 20
注册 2002-8-27
来自 Nanjing
状态 离线
[推荐阅读] 超强宝宝的精典语录
不错,如果用php的话,一个函数
array getimagesize ( string filename [, array imageinfo])
就可以
2003-11-9 07:09 PM#6
查看资料  访问主页  发短消息  QQ  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.025794 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP