圖層內img圖片自適應寬度css+js代碼
<div id=article> 圖 </div>
<script type="text/javascript" >
//縮放圖片到合適大小
function ResizeImages()
{
var myimg,oldwidth,oldheight;
var maxwidth=400;
var maxheight=555;
var imgs = document.getElementById('article').getElementsByTagName('img'); //如果你定義的id不是article,請修改此處
for(i=0;i<imgs.length;i++){
myimg = imgs[i];
if(myimg.width > myimg.height)
{
if(myimg.width > maxwidth)
{
oldwidth = myimg.width;
myimg.height = myimg.height * (maxwidth/oldwidth);
myimg.width = maxwidth;
}
}else{
if(myimg.height > maxheight)
{
oldheight = myimg.height;
myimg.width = myimg.width * (maxheight/oldheight);
myimg.height = maxheight;
}
}
}
}
//縮放圖片到合適大小
ResizeImages();
</script>
如果您的問題還未解決可以聯系站長付費協助。

有問題可以加入技術QQ群一起交流學習
本站vip會員 請加入無憂模板網 VIP群(50604020) PS:加入時備注用戶名或昵稱
普通注冊會員或訪客 請加入無憂模板網 技術交流群(50604130)
客服微信號:15898888535
聲明:本站所有文章資源內容,如無特殊說明或標注,均為采集網絡資源。如若內容侵犯了原著者的合法權益,可聯系站長刪除。