Javascript限制頁面圖片大小
來源:易賢網(wǎng) 閱讀:1302 次 日期:2015-04-17 14:18:29
溫馨提示:易賢網(wǎng)小編為您整理了“Javascript限制頁面圖片大小”,方便廣大網(wǎng)友查閱!

Javascript限制頁面圖片大小,具體代碼如下:

function limitImage(ImgD){

var areaWidth = 300; //你放置圖片區(qū)域的寬度。

var areaHeight = 300; //你放置圖片區(qū)域的高度。

var image=new Image();

image.src=ImgD.src;

if(image.width>0 && image.height>0){

flag=true;

if(image.width/image.height>= areaWidth/areaHeight){

if(image.width>areaWidth){

ImgD.width=areaWidth;

ImgD.height=(image.height*areaWidth)/image.width;

}else{

ImgD.width=image.width;

ImgD.height=image.height;

}

ImgD.alt=image.width+"×"+image.height;

}else{

if(image.height>areaHeight){

ImgD.height=areaHeight;

ImgD.width=(image.width*areaHeight)/image.height;

}else{

ImgD.width=image.width;

ImgD.height=image.height;

}

ImgD.alt=image.width+"×"+image.height;

}

}

}

更多信息請(qǐng)查看IT技術(shù)專欄

更多信息請(qǐng)查看腳本欄目
易賢網(wǎng)手機(jī)網(wǎng)站地址:Javascript限制頁面圖片大小
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn)

版權(quán)所有:易賢網(wǎng)