js同比例縮放圖片的小例子
更新時間:2013年10月30日 16:28:04 作者:
這篇文章介紹了js同比例縮放圖片的小例子,有需要的朋友可以參考一下
復(fù)制代碼 代碼如下:
function DrawImage(ImgD, FitWidth, FitHeight) {
var image = new Image();
image.src = ImgD.src;
if (image.width > 0 && image.height > 0) {
if (image.width / image.height >= FitWidth / FitHeight) {
if (image.width > FitWidth) {
ImgD.width = FitWidth;
ImgD.height = (image.height * FitWidth) / image.width;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
} else {
if (image.height > FitHeight) {
ImgD.height = FitHeight;
ImgD.width = (image.width * FitHeight) / image.height;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
}
}
}
相關(guān)文章
Bootstrap導(dǎo)航條可點擊和鼠標(biāo)懸停顯示下拉菜單的實現(xiàn)代碼
這篇文章主要介紹了Bootstrap導(dǎo)航條可點擊和鼠標(biāo)懸停顯示下拉菜單的實現(xiàn)代碼的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-06-06
JavaScript搜索字符串并將搜索結(jié)果返回到字符串的方法
這篇文章主要介紹了JavaScript搜索字符串并將搜索結(jié)果返回到字符串的方法,涉及javascript中match方法操作字符串的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-04-04
(currentStyle)javascript為何有時用style得不到已設(shè)定的CSS的屬性
(currentStyle)javascript為何有時用style得不到已設(shè)定的CSS的屬性...2007-08-08
JavaScript實現(xiàn)Sleep函數(shù)的代碼
大家知道,JavaScript中沒有內(nèi)置我們常用的sleep()函數(shù),只有定時器setTimeout()和循環(huán)定時器setInterval()2007-03-03
JavaScript在瀏覽器標(biāo)題欄上顯示當(dāng)前日期和時間的方法
這篇文章主要介紹了JavaScript在瀏覽器標(biāo)題欄上顯示當(dāng)前日期和時間的方法,實例分析了javascript操作時間及DOM節(jié)點實現(xiàn)定時觸發(fā)的技巧,非常具有實用價值,需要的朋友可以參考下2015-03-03

