[英]Custom Jquery slideshow doesn't want to reset?
在$(document).ready(function()
,我有以下代码:
num = $("#mainContentCategoryLinksWrapper > div").size();
这使num等于#mainContentCategoryLinksWrapper
的子代的长度。 目前,这等于4。在$(document).ready(function(
我有这个:
var timesRun = 0;
function slideshow(){
if(timesRun < num){
$(".arrowIn").stop().animate({color: "#a12324", textIndent: "30px", backgroundPosition: '0px 0px'}, 100, function(){ //the first child in the series has a class of "arrowIn"
$(".arrowIn").next().addClass("replaceMe"); //Adds the ".replaceMe" placeholder the the next element.
$(".arrowIn").removeClass("arrowIn"); //Deletes the class on the current element
$(".replaceMe").addClass("arrowIn").removeClass("replaceMe"); //reassigns ".arrowIn" over ".replaceMe"
timesRun = timesRun + 1; //increases number of times run
}).prev().animate({color: "#000000", textIndent: "25px", backgroundPosition: '0px -25px'}, {duration: 50}); //puts the previous element back to it's original position
}else{
timesRun = 0;
$(".arrowIn").removeClass("arrowIn");
$("#mainContentCategoryLinksWrapper:first-child").addClass("arrowIn"); //this is supposed to reset timesRun, and set the first child in the series back to the original ".arrowIn"
}
}
setInterval( 'slideshow()', 1000 );
所以这是代码的作用:
1)使4(#1)次系列中的第一个运行动画= 1 2)对4(#2)次系列中的第二个动画运行= 2 3)对4(#3)次中的第三系列运行动画= 3 4)对4(#4)timesRun = 4 5系列中的第四动画进行动画处理。现在run比num长。 将类名重置为原始的.arrowIn,将timesRun设置为0。
但是,重新执行slideshow()时,它不会重新开始。
有任何想法吗? 有关示例,请参见www.raceramps.com/v3。
在我看来,您已经在$(document).ready()
块中声明了该函数。 如果那样的话,它将肯定不会起作用,因为函数生命周期仅限于“ ready”块,并且当完成时,声明对于“ ready”块之外的任何其他元素将不可见,因此您应该做的是声明在“就绪”之外的功能如下
function slideshow(){
// your stuff
}
$(document).ready(
function () {setInterval( 'slideshow()', 1000 );
}
)
更新:尝试使重置行选择器与获取尺寸选择器相同,如下所示
$("#mainContentCategoryLinksWrapper>div:first-child").addClass("arrowIn");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.