简体   繁体   English

jQuery动画在图像上处于中间动画状态

[英]Jquery animation is getting stuck mid animation on image

I have am using a callback function on a FullPage.js site which calls a function to run a series of animation on 20 divs. 我在FullPage.js网站上使用了回调函数,该函数调用该函数在20个div上运行一系列动画。 The problem is it sometimes works, but often times breaks. 问题是它有时可行,但有时会中断。 I've realized that it breaks on 3 particular slides. 我已经意识到它会在3张特定的幻灯片上折断。 Each of them have slideshow carousels on them. 他们每个人都有幻灯片放映机。 I have reason to believe these are to blame in some shape or form. 我有理由相信这些是某种形式或形式的责任。

However, when I set the slideshow divs to display:none, the animation work flawlessly. 但是,当我将幻灯片div设置为display:none时,动画可以完美地工作。

You can see the site at question here (the slides the dont work properly are the two About sections and the Gallery section): 您可以在此处查看有问题的网站(无法正常运行的幻灯片是两个关于部分和图库部分):

http://jeanhules.com/projects/greenmonster/ http://jeanhules.com/projects/greenmonster/

Am I overlooking something here? 我在这里俯瞰什么吗? I've been coding for a while and have never experienced something like this. 我已经编码了一段时间,从未经历过类似的事情。

Example code for the small tile animation can be found here: 小图块动画的示例代码可以在这里找到:

Here is the code for the animation that gets stuck: 这是卡住的动画的代码:

(function hl() {
  var li = $('.active .tile'),
    r  = Math.floor(Math.random() * li.length),
    h  = li.eq(r).hasClass('active'),
    w  = li.filter('.active').length;

  li.eq(r).addClass('active');
  li.eq(r).find('.tileimage').animate({ top: 0 }, 300, 'easeOutBounce', function () {});

  if (w < li.length) setTimeout(hl, h ? 0 : 100);
})();

Thanks. 谢谢。 A tip is ready for anyone who helps me solve this. 为帮助我解决此问题的任何人准备了一个提示。

Just checked out your fiddle, it seems like your second function h1 finishes looping in about 1000 ms which works when masterAdd() has a timeout of 1000ms but when you increase it to 1500ms h1's while loop ends prematurely. 刚刚检查了您的提琴,看来您的第二个函数h1大约在1000 ms内完成了循环,当masterAdd()的超时为1000ms时有效,但是当您将其增加到1500ms时,h1的while循环将提前结束。 If you increase your h1's setTimeout function to 150, it should animate all the tiles. 如果将h1的setTimeout函数增加到150,则它应该为所有图块设置动画。

Forked your fiddle and tested it out: http://jsfiddle.net/us6n382k/ 分叉您的小提琴并对其进行了测试: http : //jsfiddle.net/us6n382k/

if (w < li.length) setTimeout(hl, h ? 0 : 150); //was 100

Hope that helps! 希望有帮助!

I have a feeling it has to do with the fact that when you randomly select a tile to animate, it may be a tile that has already been animated, but the animation is not yet complete. 我觉得这与以下事实有关:当您随机选择要进行动画处理的图块时,它可能是已经过动画处理的图块,但动画尚未完成。 You could use the :not() selector to avoid that: 您可以使用:not()选择器来避免这种情况:

function randomInt(count) {
    return Math.floor(Math.random() * count);
}

(function activateSlide() {
    var $inactiveSlides = $('[id^="slide"]:not(.active)'),
        count  = $inactiveSlides.length;
    $inactiveSlides.eq(randomInt(count)).addClass('active');
    if (count > 1) {
        setTimeout(activateSlide, 500);
    }
})();

(function activateTile() {
    var $inactiveTiles = $('.active').find('.tile:not(.active)'),
        count  = $inactiveTiles.length;
    $inactiveTiles.eq(randomInt(count)).addClass('active').find('.tileimage').animate({ top: 0 }, 300, 'easeOutBounce');
    if (count > 1) {
        setTimeout(activateTile, 100);
    }
})();

jsfiddle 的jsfiddle

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

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