
这是很多网页前端设计者都面临的一个问题,今天通过收集整理,把我常用的方法贴出来,希望能对需要的同行朋友有点帮助~~首称贴一段js代码:<script type="text/javascript">var Image = {}function SetMiddle(image, height){/// <summary>重设
图片大小后让图片相对于DIV居中</summary>if (typeof(image) == 'string') image = document.images[image] || document.getElementById(image)var div = image.parentNodeif(div.nodeName != "DIV"){div = div.parentNode}if(image.height >0 &&image.height <height){var marginTopVal= (height - image.height) / 2image.style.marginTop =parseInt(marginTopVal)+"px"///不加px,在火狐下不支持!}else{image.height = heightimage.style.marginTop = "0px"}}Image.Resize1=function(image,width,height){if(width==null||height==null)returnimage.removeAttribute('width')image.removeAttribute('height')var w = image.width, h = image.heightvar scalingW=w/width,scalingH=h/heightvar scaling = w / hif(scalingW>=scalingH){image.width=widthimage.height = width / scaling}else{image.height=heightimage.width = height*scaling}}function imgReSize(imgObj,w,h){Image.Resize1(imgObj,w,h)SetMiddle(imgObj,h)}</script>下面是具体的图片调用js函数的方法:onload=imgReSize(this,628,452)函数有三个参数,第一个就不用说了吧,每二个参数是说图片的
最大宽度,第三个参数是表示图片的最大
高度当图片的宽高任一个大于参数里设置的值的时候,图片就会等比例缩小,且位置相对于外面的容器左右居中多的不说了,你懂的~~~<div style="max-height:500pxoverflow:auto"></div>
max-height是最大高度,除了ie6不支持,需要使用js外,其他ie7+,ff,chrome都支持,符合你的要求
也可以用纯js
<div id="test" style="overflow:auto"></div>
<script>
var 最大高度 = 300
function a(){
if($('#test')[0].offsetHeight >最大高度) $('#test').height(最大高度)
}//你怎么调用a()就看你的了
</script>
设置css:min-height:you min heightmax-height:200pxoverflow-y:auto//加竖滚动条
你这是extjs吧,大体是这样的,估计就是属性名称不一样而已,你查查哦,我对extjs不是很了解
评论列表(0条)