Javascript 使用简单滑块的jquery堆栈溢出
我对现有的滑块不满意(主要是因为它们是臃肿的代码,需要外部脚本调用),于是决定尝试编写一个简单的、特定于站点的内联滑块脚本。但是,我得到一个堆栈溢出错误Javascript 使用简单滑块的jquery堆栈溢出,javascript,jquery,Javascript,Jquery,我对现有的滑块不满意(主要是因为它们是臃肿的代码,需要外部脚本调用),于是决定尝试编写一个简单的、特定于站点的内联滑块脚本。但是,我得到一个堆栈溢出错误 <div id="featured"> <div class="tween"> <div class="cropimg"> </div> <div class="container">
<div id="featured">
<div class="tween">
<div class="cropimg">
</div>
<div class="container">
text
</div>
</div>
<div class="tween">
<div class="cropimg">
</div>
<div class="container">
text
</div>
</div>
<div class="tween">
<div class="cropimg">
</div>
<div class="container">
text
</div>
</div>
</div>
<script>
var _rys = jQuery.noConflict();
_rys("document").ready(function(){
var timeOut = 5000;
setTimeout(nextSlide(1),timeOut);
});
function nextSlide(next) {
var i = 1;
var numberOfChildren = _rys("#featured").children().length;
_rys(".tween:nth-child("+next+")").fadeTo(500,1);
while (i<=numberOfChildren) {
// loop through the children and make those that are opaque invisible
if (i != next) {
if (_rys(".tween:nth-child("+i+")").css('opacity') != 0) {
_rys(".tween:nth-child("+i+")").css('opacity',0);
}
}
i++;
}
if (next>=numberOfChildren) {
setTimeout(nextSlide(1), 5000);
} else {
setTimeout(nextSlide(next+1), 5000);
}
}
</script>
文本
文本
文本
var_rys=jQuery.noConflict();
_rys(“文件”).ready(函数(){
var超时=5000;
setTimeout(nextSlide(1),timeOut);
});
函数nextSlide(下一个){
var i=1;
var numberOfChildren=_rys(“#特色”).children().length;
_rys(“.tween:n个孩子(+next+”)).fadeTo(500,1);
while(i=numberOfChildren){
setTimeout(nextSlide(1),5000);
}否则{
setTimeout(nextSlide(next+1),5000);
}
}
这应该是setTimeout(function(){nextSlide(1)},timeOut)对于每个setTimeout()调用,代码>等。使用setTimeout(nextSlide(1),timeOut)
,则递归调用nextSlide()
方法,而不将其放入事件队列(无延迟),而是放入返回值(此处未定义)。仅供参考,您的while
循环实际上并不是最好的done@UmairShahYousafzai当你在没有自己搜索过的情况下提问时:)\u-rys(.tween:not(:nth child(+i+)).css('opacity',0)代码>就足够了,没有任何而循环就够了,A.沃尔夫@泰克提夫:啊哈……我的错……只是谷歌搜索了一下,我惊讶地发现这是太多的基本问题了这应该是setTimeout(function(){nextSlide(1)},timeOut)对于每个setTimeout()调用,代码>等。使用setTimeout(nextSlide(1),timeOut)
,则递归调用nextSlide()
方法,而不将其放入事件队列(无延迟),而是放入返回值(此处未定义)。仅供参考,您的while
循环实际上并不是最好的done@UmairShahYousafzai当你在没有自己搜索过的情况下提问时:)\u-rys(.tween:not(:nth child(+i+)).css('opacity',0)代码>就足够了,没有任何而循环就够了,A.沃尔夫@泰克提夫:啊哈……我的错……只是谷歌搜索了一下,我惊讶地发现这是太多的基本问题了D