我想要jQuery slideToggle效果,但想要使用CSS3转换来调用iOS设备上的图形处理器,这样转换就会更流畅。
发布于 2012-01-14 15:05:07
你可以通过转换height,padding和border-width来实现这一点。下面是一个例子:
$('.run-css').click(function() {
$('.cont').toggleClass('toggled');
});.cont {
width: 100px;
height: 100px;
border: 1px #CCC solid;
background-color: #EEE;
padding: 5px;
-webkit-transition: height .3s linear, padding-top .3s linear, padding-bottom .3s linear, border-top-width .3s linear, border-top-width .3s linear;
transition: height .3s linear, padding-top .3s linear, padding-bottom .3s linear, border-top-width .3s linear, border-top-width .3s linear;
}
.toggled {
overflow: hidden;
padding-top: 0;
padding-bottom: 0;
height: 0;
border-width: 0 1px;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<button class="run-css">CSS slideToggle</button>
<div class="cont">Toggle this div</div>
发布于 2012-12-19 05:54:46
很抱歉,除非您知道确切的高度,否则CSS3不支持此功能。无法在0和auto之间设置动画。如果你知道确切的高度,你可以在这里生成一些转换代码:http://css3generator.com/
发布于 2013-08-15 22:09:28
为真,您不能在0和自动高度之间设置动画,但您实际上可以切换最大高度。
在max-height:0和max-height:1000px之间切换(通过JS),您将获得所获得的结果,尽管它不会像jQuery的slideToggle函数那样流畅。
再加上不透明的淡入淡出效果,看起来相当不错。我强烈建议只在相对较短的容器上使用此技术,因为较大的容器可以创建抖动的动画。
https://stackoverflow.com/questions/8860631
复制相似问题