圖片按比例縮放函數(shù)
更新時(shí)間:2006年06月26日 00:00:00 作者:
以下是程序代碼:
<script language="JavaScript">
<!--
//圖片按比例縮放
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
//參數(shù)(圖片,允許的寬度,允許的高度)
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//-->
</script>
調(diào)用:<img src="images/toplogo.gif" onload="javascript:DrawImage(this,100,100)">
<!--
//圖片按比例縮放
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
//參數(shù)(圖片,允許的寬度,允許的高度)
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//-->
</script>
調(diào)用:<img src="images/toplogo.gif" onload="javascript:DrawImage(this,100,100)">
相關(guān)文章
微信小程序 仿貓眼實(shí)現(xiàn)實(shí)例代碼
這篇文章主要介紹了微信小程序 仿貓眼實(shí)現(xiàn)實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2017-03-03微信小程序 數(shù)組(增,刪,改,查)等操作實(shí)例詳解
這篇文章主要介紹了微信小程序 數(shù)組(增,刪,改,查)等操作實(shí)例詳解的相關(guān)資料,這里對(duì)小程序的數(shù)組進(jìn)行操作,簡單實(shí)例,需要的朋友可以參考下2017-01-01微信小程序 向左滑動(dòng)刪除功能的實(shí)現(xiàn)
這篇文章主要介紹了微信小程序 向左滑動(dòng)刪除功能的實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2017-03-03輸入框跟隨文字內(nèi)容適配寬實(shí)現(xiàn)示例
這篇文章主要為大家介紹了輸入框跟隨文字內(nèi)容適配寬實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08微信小程序 新建登錄頁并實(shí)現(xiàn)tabBar隱藏
這篇文章主要介紹了微信小程序 新建登錄頁并實(shí)現(xiàn)tabBar隱藏的相關(guān)資料,需要的朋友可以參考下2017-06-06javascript的setTimeout()使用方法總結(jié)
這篇文章主要給大家分享javascript的setTimeout()使用方法總結(jié),js的setTimeout方法用處比較多,通常用在頁面刷新了、延遲執(zhí)行了等等,下面我們一起來看看文章對(duì)該內(nèi)容的具體總結(jié)吧,需要的朋友可以參考一下2021-11-11