关于transition让height:auto 失效的问题

<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>

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值