تتعطل مؤقتات jQuery بعد دورتين
سؤال
لدي مؤقت jQuery قيد التشغيل ويبدو أنه يتعطل بعد دورتين: Treethink.treethink.net/backup
في الوقت الحالي، في توقيتات مختلفة، سيتم سحب شريط الأخبار وتغيير القسم الذي يظهر ثم إخراجه مرة أخرى.بعد عدة دورات، والتي يمكنك رؤيتها في الرابط أعلاه، يبقى بعضها لفترة أطول ثم يتداخل ويصبح الأمر في حالة من الفوضى.لست متأكدا لماذا يحدث هذا ...
هنا هو الكود الخاص بي:
/* Retracting Ticker */
/* Initially hide all news items */
$('#ticker1').hide();
$('#ticker2').hide();
$('#ticker3').hide();
$("#ticker1").oneTime(1000,function(i) { /* Show 1 once on first pull out */
$('#ticker1').show();
});
$("#ticker1").everyTime(64500,function(i) { /* Hide 3 and show 1 everytime timer gets to certain point */
$('#ticker1').show();
});
$("#ticker1").oneTime(21500,function(i) { /* Hide 1 and show 2 once after first pull out */
$('#ticker1').hide();
$('#ticker2').show();
});
$("#ticker1").everyTime(86000,function(i) { /* Hide 1 and show 2 everytime timer gets to certain point */
$('#ticker1').hide();
$('#ticker2').show();
});
$("#ticker2").oneTime(43000,function(i) { /* Hide 2 and show 3 once after second pull out */
$('#ticker2').hide();
$('#ticker3').show();
});
$("#ticker2").everyTime(107500,function(i) { /* Hide 2 and show 3 everytime timer gets to certain point */
$('#ticker2').hide();
$('#ticker3').show();
});
$("#ticker3").oneTime(64000,function(i) { /* Hide 2 and show 3 once after second pull out */
$('#ticker3').hide();
});
$("#ticker3").everyTime(129000,function(i) { /* Hide 2 and show 3 everytime timer gets to certain point */
$('#ticker3').hide();
});
$("#ticker").oneTime(2000,function(i) { /* Do the first pull out once */
$("#ticker").animate({right: "0"}, {duration: 800 });
});
$("#ticker").oneTime(20000,function(i) { /* Do the first retract once */
$("#ticker").animate({right: "-450"}, {duration: 800});
});
$("#ticker").everyTime(21500,function(i) { /* Everytime timer gets to certain point */
$("#ticker").animate({right: "0"}, {duration: 800}); /* Pull out right away */
$("#ticker").oneTime(20000,function(i) { /* Retract once */
$("#ticker").animate({right: "-450"}, {duration: 800});
});
});
شكرًا،
وايد
المحلول
دعونا نتجاهل كل oneTime
لأنهم لن يفسدوك.
$("#ticker1").everyTime(64500,function(i) {
$('#ticker1').show();
});
$("#ticker1").everyTime(86000,function(i) {
$('#ticker1').hide();
$('#ticker2').show();
});
$("#ticker2").everyTime(107500,function(i) {
$('#ticker2').hide();
$('#ticker3').show();
});
$("#ticker3").everyTime(129000,function(i) {
$('#ticker3').hide();
});
$("#ticker").everyTime(21500,function(i) {
$("#ticker").animate({right: "0"}, {duration: 800});
$("#ticker").oneTime(20000,function(i) {
$("#ticker").animate({right: "-450"}, {duration: 800});
});
});
لديك 4 كائنات:المؤشر والحاوية و3 رسائل.
سلوك الحاوية هو هذا (تقريبًا، دون احتساب عملية السحب الأولى):كل 21.5 ثانية، قم بالاختباء لمدة 1.5 ثانية ثم انزلق مرة أخرى للخارج.حسنًا، هذا ليس مصدر المشكلة، مؤقتات الرسائل الثلاثة هي المشكلة.
هذا هو سلوك الرسالة على فترات:
ticker show (s) hide (s)
1 64.5 86
2 86 107.5
3 107.5 129
يحرر لقد أخطأت في أرقامي خلال الفاصل الزمني الأول للمؤشر، لكنني ما زلت أعتقد أن الفكرة هي نفسها.في نهاية المطاف، تتداخل الأوقات.