源码网 - 中国第一源码门户
选择镜像:网通镜像 - 电信主站
会员登录/控制面版您的位置: 学院首页 >> 网页制作 >> Javascript >> 详细内容
 

推荐文章

  • 悟透JavaScript
 
 

热点文章

  • 腾讯迷你天气预报代码
  • js:window.onload事件
  • Javascript 遮罩层 兼容性好。支持IE,firefox 页面变灰..
  • jQuery是什么,jQuery入门简介
  • JavaScript实现图片幻灯片效果的源代码
  • 北京2008年奥运会金牌排行榜 调用163
  • 图片自动转换的js代码
  • 右下角浮动广告代码(仿QQ)
  • JavaScript使用Window对象
  • js与flash的函数交互
  • prototype.js之ajax.request
  • javascript汉字转拼音 功能块,方法很笨但很实用
 
 

相关文章

  • 用Javascript使网页图片产生旋转效果
 
 

网页图片按比例缩放代码

  • 阅览次数:
  • 文章来源: CodePub整理
  • 原文作者:
  • 整理日期: 2008-10-02
  • 发表评论
  • 字体大小:
  • 小
  • 中
  • 大

<script language="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 src="图片" onload="javascript:drawImage(this,100,100)" width=100 height=100>

上一篇:FreeBSD 7.1 Beta 2
下一篇:Python 3.0 一个巨大的改变
  • 网友评论:
  • 查看所有评论
  • 我要发表评论
您的网名:
留言主题:
你要发表的内容: