0
私はdivのバックグラウンド位置を-250pxで変更しています。私の仕事は機能していますが、最悪の形でやり遂げられたと確信しており、簡単にすることを望みます。繰り返しJquery関数
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-250px top');
next();
});
私はそれが-6500pxに達するまで、各チャンクはちょうど-250px差を有すると同じ4行26回繰り返していないよように、これを変更する方法がある場合、私は興味がありました。
何か洞察力があれば幸いです。ありがとうございました。
編集:deppermさんのリクエストに応じて、完全な機能: 完全な機能は次のとおりです。それぞれ異なる背景イメージを持つX個のアイテムがあり、それぞれに同じ機能を使用しています。あなたは、コードのあなたの4行26回を繰り返したくない場合は
$('.the-item').mouseenter(function(){
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-250px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-500px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-750px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-1000px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-1250px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-1500px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-1750px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-2000px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-2250px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-2500px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-2750px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-3000px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-3250px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-3500px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-3750px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-4000px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-4250px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-4500px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-4750px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-5000px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-5250px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-5500px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-5750px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-6000px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-6250px top');
next();
});
$(this).delay(25).queue(function (next) {
$(this).css('background-position', '-6500px top');
next();
});
});
はあなたの関連するコードの残りの部分を追加することができますか? – depperm
アニメーションの間にデュレーションが必要な場合は、 'setInterval()'を使います。 https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval – bipen