<script type="text/javascript">   
//自动适应宽,原版    
$(function(){   
var maxwidth = 310;   
var html = '';   
$('.prolistshowimg a img').html(html);   
$(".prolistshowimg a img").each(function(i){    
var proImg = new Image();   
var image = $(this);   
//alert(this.src);    
proImg.onload = function(){   
if(proImg.width > maxwidth ){image.width(maxwidth);}     
}   
proImg.src = this.src;      
});   
});   
  
//自动适就宽高,改动    
$(function(){   
var max_w=172;   
var max_h=113;   
var m1=max_w/max_h;   
var html = '';   
$(".proListShow").html(html);   
$(".proListShow").each(function(i){   
var proImg = new Image();   
var image = $(this);   
//alert(this.src);    
proImg.onload = function(){   
var m2 = proImg.width/proImg.height;   
if(m2 > m1){   
image.width(max_w);   
}else{   
image.height(max_h);   
}   
}   
proImg.src = this.src;      
});   
});  
</script>   

 

1、自适应宽:

<div class="prolistshowimg">  
<a href="#">  
<img src="abc.jpg" />  
</a>  
</div>  

2、自适应宽高:

<img src="abc.jpg" class="proListShow" />  

 

posted on 2012-05-30 20:17  rooly  阅读(562)  评论(0)    收藏  举报