Set max-height using javascript
I have a div, and the maximum width for this div is user d开发者_如何学编程efined. I know I can get it done using element.style.height but this doesn't work in IE.
Any ideas on how to implement the max-height equivalent of Firefox by using javascript?
Usually style attribute names are translated into javascript property names by removing the hyphens and camelcase the name instead.
So background-color
becomes backgroundColor
, text-align
becomes textAlign
and max-height
becomes maxHeight
.
You can set an element el
's maximum height to mHeight
by:
el.style.maxHeight=mHeight;
Remember to use a valid value for mHeight
.
document.getElementById ( "yourelementid" ).style.maxHeight = "100px";
See maxHeight Property
maxHeight was introduced in Windows Internet Explorer 7
To make the animation time match what is expected, I would use el.scrollHeight
to find the required height of the element.
精彩评论