[英]jQuery Animate: Callback Called Twice
I'm triggering a set of animations when an user scrolls down on a website (using afterMove callback from onepage-scroll ) and, when animating some elements, unexpectedly, the same function is called multiple times.当用户在网站上向下滚动时(使用来自onepage-scroll 的afterMove 回调),我触发了一组动画,并且在为某些元素设置动画时,意外地多次调用相同的函数。
Using this, I don't have a problem:使用这个,我没有问题:
base = $('section[data-index="' + index + '"]');
base.find('h1').animate({opacity: 0.1}, 3000);
console.log('Finished #' + index);
And I have the correct output on console after moving to section #3.移动到第 3 部分后,我在控制台上有正确的输出。
Finished #2
Finished #3
But when I try to use a form, for instance,但是当我尝试使用表单时,例如,
base.find('#my-form-id').animate({opacity: 0.1}, 3000);
this is the output:这是输出:
Finished #2
Finished #3
Finished #2
Finished #3
The last two logs are registered only when the animation ends.最后两个日志仅在动画结束时注册。
What's resulting this behaviour?是什么导致了这种行为?
Actually, I was searching in the wrong place.其实我找错地方了。
The real problem was that I was styling the element with a CSS3 opacity transition.真正的问题是我使用 CSS3 不透明度过渡来设置元素的样式。 When I tried to apply any other action to the same element which would use the same attributes, I had this issue.当我尝试将任何其他操作应用于将使用相同属性的同一元素时,我遇到了这个问题。
It seems that they doesn't play nicely together.看起来他们在一起玩得并不好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.