简体   繁体   English

同时jQuery动画

[英]Simultaneous jQuery Animations

I'm trying to get both a fadeIn (opacity toggle) and border fade (using jquery-animate-colors ) to fire simultaneously but I'm having some trouble. 我试图让fadeIn(不透明度切换)和边框淡入淡出(使用jquery-animate-colors )同时触发但我遇到了一些麻烦。 Can someone help review the following code? 有人可以帮助查看以下代码吗?

$.fn.extend({
  key_fadeIn: function() {
    return $(this).animate({
      opacity: "1"
    }, 600);
  },
  key_fadeOut: function() {
    return $(this).animate({
      opacity: "0.4"
    }, 600);
  }
});

fadeUnselected = function(row) {
  $("#bar > div").filter(function() {
    return $(this).id !== row;
  }).key_fadeOut();
  return $(row).key_fadeIn();
};

highlightRow = function(row, count) {
  return $(row).animate({
    "border-color": "#3737A2"
  }).animate({
    "border-color": "#FFFFFF"
  }).animate({
    "border-color": "#3737A2"
  }).animate({
    "border-color": "#FFFFFF"
  });
};


fadeUnselected("#foo");
highlightRow("#foo"); // doesn't fire until fadeUnselected is complete

Would really appreciate it. 真的很感激。 Thanks! 谢谢!

By default, JQuery places animations in the effects queue so they will happen one after another. 默认情况下,JQuery将动画放置在效果队列中,以便它们一个接一个地发生。 If you want an animation to happen immediately set the queue:false flag in your animate options map. 如果要立即发生动画,请在动画选项图中设置queue:false标志。

For example, in your case, 例如,在您的情况下,

$(this).animate({
      opacity: "1"
    }, 600);

would become 会成为

$(this).animate(
{
    opacity: "1"
}, 
{
    duration:600,
    queue:false
});

You'd likely want to use the options map and set the queue for the border animation as well. 您可能希望使用选项映射并为边框动画设置队列。

http://api.jquery.com/animate/ http://api.jquery.com/animate/

$.fn.extend({
  key_fadeIn: function() {
    return $(this).animate({
      opacity: "1"
    }, { duration:600, queue:false });
  },
  key_fadeOut: function() {
    return $(this).animate({
      opacity: "0.4"
    }, { duration:600, queue:false });
  }
});

fadeUnselected = function(row) {
  $("#bar > div").filter(function() {
    return $(this).id !== row;
  }).key_fadeOut();
  return $(row).key_fadeIn();
};

highlightRow = function(row, count) {
  return $(row).animate({
    "border-color": "#3737A2"
  }).animate({
    "border-color": "#FFFFFF"
  }).animate({
    "border-color": "#3737A2"
  }).animate({
    "border-color": "#FFFFFF"
  });
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM