码迷,mamicode.com
首页 > Web开发 > 详细

JS创建缩略图

时间:2015-02-12 18:00:30      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:

<script  language="javascript"> 
//显示缩略图
function DrawImage(ImgD,width_s,height_s){
 /*var width_s=139;
 var height_s=104;
 */
 var image=new Image();
 image.src=ImgD.src;
 if(image.width>0 && image.height>0){
 flag=true;
 if(image.width/image.height>=width_s/height_s){
 if(image.width>width_s){
 ImgD.width=width_s;
 ImgD.height=(image.height*width_s)/image.width;
 }else{
 ImgD.width=image.width;
 ImgD.height=image.height;
 }
 }
 else{
 if(image.height>height_s){
 ImgD.height=height_s;
 ImgD.width=(image.width*height_s)/image.height;
 }else{
 ImgD.width=image.width;
 ImgD.height=image.height;
 }
 }
 }
 /*else{
 ImgD.src="";
 ImgD.
 }*/
 }
 </script>


调用
<div><img src="图片" align="center" onload="DrawImage(this,200,200)"></div>

 

JS创建缩略图

标签:

原文地址:http://www.cnblogs.com/xuzai/p/4288337.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!