平滑这个jQuery切换动画?

前端之家收集整理的这篇文章主要介绍了平滑这个jQuery切换动画?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的jQuery函数生成的动画很不稳定,我一直在寻找不同的SO解决方案,例如添加 jquery.easing,但没有运气.问题是每个div中的iframe吗?

关于如何平滑动画的任何想法?我的基本切换功能是最好的方法吗?

JSFiddle:http://jsfiddle.net/gwLcD/8/

基本标记在下面,并在页面上重复多次(每个“videotoggle”div之间有文本块):

  1. <div class="videotoggle">
  2.  
  3. <p><h2 class="entry-title">View a few minutes of the (title) video </h2></p>
  4.  
  5. <div class="videoblock">
  6.  
  7. <iframe width="560" height="315" src="http://www.youtube.com/embed/????????"
  8. frameborder="0" allowfullscreen></iframe>
  9.  
  10. </div></div>

功能

  1. $(document).ready(function(){
  2. $(".videoblock").hide(); //closes all divs on first page load
  3. $(".entry-title").click(function() {
  4. $this = $(this); //this next code only allows one open div at a time
  5. $content = $this.closest('.videotoggle').find(".videoblock");
  6. if (!$this.is('.active-title')) {
  7. $('.active-title').removeClass('active-title');
  8. $this.addClass('active-title');
  9. $(".videoblock:visible").slideToggle(400); //slide toggle
  10. $content.slideToggle(400);
  11. }
  12. });
  13. });

解决方法

安德鲁的解决方案是正确的,但我仍然会把这样的CSS(如果javascript关闭):
.videoblock {宽度:560像素;身高:315px;溢出:隐藏}

添加同步动画:

  1. $('.videoblock').css('height','0');
  2. $(".entry-title").click(function() {
  3. $this = $(this);
  4. $content = $this.closest('.videotoggle').find(".videoblock");
  5. if (!$this.is('.active-title')) {
  6.  
  7. $('.active-title').removeClass('active-title');
  8. $this.addClass('active-title');
  9. $(".videoblock:visible").animate({height: "0"},{ duration: 400,queue: false });
  10. $content.animate({height: "315"},queue: false });
  11. }
  12. });

以下是决赛的链接http://jsfiddle.net/gwLcD/21/

猜你在找的jQuery相关文章