閒著,用原生javascript寫了個 一個固定寬高的div框內,等比圖片放縮
外加水平/垂直居中javascript特效,希望對各位童鞋有用,或者有什麼該完善的。0.0
<script type="text/javascript">
function showImgH_W2(tr,qW,qH){
var sdgH,sdgW,j2;
sdgW=tr.width;
sdgH=tr.height;
if(sdgW>sdgH){
tr.style.width=qW+"px";
//var rr=qH;
j2=(qH-(qW/sdgW)*sdgH)/2;
if(j2>0)
tr.style.paddingTop=j2+"px";
}
else{
tr.style.height=qH+"px";
//var rr=200;
j2=(qW-(qH/sdgH)*sdgW)/2;
if(j2>0)
tr.style.paddingLeft=j2+"px";
}
}
//window.onload=showImgH_W;
</script>