如何获得与jQuery的slideToggle使用CSS 3转换相同的效果?

前端之家收集整理的这篇文章主要介绍了如何获得与jQuery的slideToggle使用CSS 3转换相同的效果?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想要jQuery slideToggle效果,但是想要使用CSS3转换,以便在iOS设备上调用GPU,以便转换更平滑。

解决方法

您可以通过转换高度,填充和边框宽度来实现此目的。这是一个例子:
  1. $('.run-css').click(function() {
  2. $('.cont').toggleClass('toggled');
  3. });
  1. .cont {
  2. width: 100px;
  3. height: 100px;
  4. border: 1px #CCC solid;
  5. background-color: #EEE;
  6. padding: 5px;
  7. -webkit-transition: height .3s linear,padding-top .3s linear,padding-bottom .3s linear,border-top-width .3s linear,border-top-width .3s linear;
  8. transition: height .3s linear,border-top-width .3s linear;
  9. }
  10. .toggled {
  11. overflow: hidden;
  12. padding-top: 0;
  13. padding-bottom: 0;
  14. height: 0;
  15. border-width: 0 1px;
  16. }
  1. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
  2. <button class="run-css">CSS slideToggle</button>
  3.  
  4. <div class="cont">Toggle this div</div>

猜你在找的jQuery相关文章