0
2400msごとに「チック」をトリガーするクロックがあります。 「チック」では親のdivの子をtoggleClassにしたいが、同時にすべてではない:親のインデックスを使用してトリガーを時間的にオフセットして、ある種の波で起こるようにする。 それに加えて、私はそれをやり始めたはずですが、私はユーザーがスクロールしている間にこれが起こらないようにしています。 私はコンテナに.off()でティックを聞くのを止めることができましたが、私はオフセットの原因となるタイムアウトをクリアすることはできません。。範囲外のjQueryタイムアウトをクリアする
ここjsfiddleです:https://jsfiddle.net/andinse/w878ft4z/7/
私はjQueryのに新しいですし、少しはこのすべての入れ子に失われました。
大変助かりました!
var $parents = $('.parents');
var $parent = $('.parent');
var $child = $('.child');
var $speed = 2400;
var $loopLength = 5;
setInterval(function clock() {
$parents.trigger('tic');
}, $speed);
$.fn.play = function() {
$(this).on('tic', function() {
$child.each(function() {
var $that = $(this);
var $offset = ($that.parent().index() % $loopLength) * $speed/$loopLength;
setTimeout(function() {
$that.toggleClass('special');
}, $offset);
});
return this;
});
};
$parents.play();
$(document).scroll(function() {
$parents.off('tic');
clearTimeout($.data(this, 'scrollTimer'));
$.data(this, 'scrollTimer', setTimeout(function() {
$parents.play();
}, 200));
});