這個功能主要是解決內容頁中的圖片過大撐出,導致頁面比較難看,就需要這樣的代碼,需要的朋友可以參考下
需求:圖片width<=600px,height<=800。
1、利用max-width,max-height使圖片等比例自動縮放
代碼:
復制代碼 代碼如下:
img{max-width: 600px;max-height: 800px;}
復制代碼 代碼如下:
var img_width = img.OffsetWidth;<BR>var img_height = OffsetHeight;
var current_w = (150*img_width)/img_height;
var current_h = (330*img_height)/img_width;
if(img_height>150){
if(img_width>330){
D.css(img,{
width:330 + "px",
height:current_h + "px"
})
}else{
D.css(img,{
width:current_w + "px",
height:150 + "px"
})
}
}else{
if(img_width>330){
D.css(img,{
width:330 + "px",
height:current_h + "px"
})
}else{
D.css(img,{
width:img_width + "px",
height:img_height + "px"
})
}
}
新聞熱點
疑難解答
圖片精選