jQueryサイクルのプラグインの異なるタイムアウト値を各スライド

StackOverflow https://stackoverflow.com/questions/3075073

  •  28-09-2019
  •  | 
  •  

質問

私は利用しようと、jQueryのサイクルのプラグインのサイクル丸異なりますしたいと思っている引用表示されない全く当てはまらないのに応じて時間の長さを見積させていただきます。そのために取得し、コンテンツmangagementシステムの出力量の秒としてのクラス名などのdur13が13秒です。

これが私の業務のない試み:

$('.featureFade').cycle({cycleTimeout: 10, after: onCycleAfter});

function onCycleAfter() { 
    $('.featureFade').cycle('pause');
    var duration = $(this).attr('class').substring($(this).attr('class').indexOf('dur')+3)
    setTimeout(oncycleEnd, duration * 1000); 
}
function oncycleEnd() { 
    $('.featureFade').cycle('resume');
}

ここでのサーベイを行います。ない場合があるのもプラグインが。私は不要なのかもしれません妄の影響だけで整列する。

多くん

役に立ちましたか?

解決

timeoutFn オプション を使用することができようになります:

$('.featureFade').cycle({
  timeoutFn: function(currElement, nextElement, opts, isForward) { 
    var duration = $(currElement).attr('class').substring($(currElement).attr('class').indexOf('dur')+3)
    return duration * 1000;
  }
});

しかし、代わりにクラスのご利用でき データ属性, うようになります:

<img data-duration="2000" src="..." />

そのコードは簡単な:

$('.featureFade').cycle({
  timeoutFn: function(currElement, nextElement, opts, isForward) { 
    return parseInt($(currElement).attr('data-duration'), 10);
  }
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top