闲着,用原生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>
时间: 2024-09-12 07:00:38