加入收藏 设为首页 联系站长
WEB2.0教程 | CSS教程 | HTML教程 | 设计素材 | CSS 模板 | CSS酷站欣赏 | CSS布局实例 | Javascript | 建站代码 | 专业软件 | 常见问题 | 内容搜索
>首页 -> Javascript -> Javascript源码

TOP

用js写的图片按比例缩略代码

[ 录入者:ahwdc | 时间:2008-01-29 02:54:31 | 作者: | 来源: | 浏览:0次 ]

img.js
CODE:
//使用onload=DrawImage(this,长,宽);
function DrawImage(ImgD,w,h){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= w/h){
if(image.width>w){
ImgD.width=w;
ImgD.height=(image.height*w)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
//ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>h){
ImgD.height=h;
ImgD.width=(image.width*h)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
//ImgD.alt=image.width+"×"+image.height;
}
}
}
调用方法:
1、当然还是先在要用的页面调用这个JS
<script src="/js/img.js"></script>

2、在要缩略的图片上加上 onload=DrawImage(this,长,宽)
例如:<img src="#" onload="DrawImage(this,60,60)"

[上一篇]定时关闭的背投广告代码 [下一篇]没有了

评论

称  呼:
内  容:

相关栏目

最新文章

热门文章

推荐文章

相关文章

推荐浏览

中国百度网
安徽皖一月嫂家政
犯罪现场