CSS3 如何让height:auto实现transition过渡效果

来源:互联网 发布:js 对象添加属性和值 编辑:程序博客网 时间:2024/06/04 18:31

代码如下


<body><script typet="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script><style type="text/css">.oh{overflow:hidden;}.box{max-height:30px;transition: max-height 1s;-moz-transition: max-height 1s;/* Firefox 4 */-webkit-transition: max-height 1s;/* Safari 和 Chrome */-o-transition: max-height 1s;/* Opera */background:#ccc;}/* 关键在于指定一个大于元素在height:auto 时的高度的值,让元素过渡到一个达不到的height值,这样就模拟了height:auto过渡的效果注意max-height不可设置太大,否则效果不明显*/.box-h{max-height:120px;}</style><script type="text/javascript">function boxClick(){$(".box").toggleClass("box-h");}</script><div class="box oh" onclick="boxClick()"><div style="padding:5px 0px;">效果</div><div style="padding:5px 0px;">效果</div><div style="padding:5px 0px;">效果</div></div></body>


原创粉丝点击