Javascript 将此脚本块放在何处,以便此幻灯片可以自动移动?
我之前问了一个关于如何自动采取行动的问题,有人在这一页上回答了我的问题(有12票): 似乎代码对大多数人都有效,但我无法让它对我有效。我使用了原始的演示文件,并将代码放在jquery.blinds-0.9.js的最底部,就在“}”(jquery);”之后,但幻灯片仍然没有移动。我做错了什么?我检查了类名,它们是正确的 这就是那个脚本块:Javascript 将此脚本块放在何处,以便此幻灯片可以自动移动?,javascript,jquery,slideshow,Javascript,Jquery,Slideshow,我之前问了一个关于如何自动采取行动的问题,有人在这一页上回答了我的问题(有12票): 似乎代码对大多数人都有效,但我无法让它对我有效。我使用了原始的演示文件,并将代码放在jquery.blinds-0.9.js的最底部,就在“}”(jquery);”之后,但幻灯片仍然没有移动。我做错了什么?我检查了类名,它们是正确的 这就是那个脚本块: var SlideChanger = function(seconds_each) { var index = -1; // on the firs
var SlideChanger = function(seconds_each) {
var index = -1;
// on the first cycle, index will be set to zero below
var maxindex = ($(".change_link").length) - 1;
// how many total slides are there (count the slide buttons)
var timer = function() {
// this is the function returned by SlideChanger
var logic = function() {
// this is an inner function which uses the
// enclosed values (index and maxindex) to cycle through the slides
if (index == maxindex)
index = 0; // reset to first slide
else
index++; // goto next slide, set index to zero on first cycle
$('.slideshow').blinds_change(index); // this is what changes the slide
setTimeout(logic, 1000 * seconds_each);
// schedule ourself to run in the future
}
logic(); // get the ball rolling
}
return timer; // give caller the function
}
SlideChanger(5)(); // get the function at five seconds per slide and run it
尝试包装最后一行
SlideChanger(5)()代码>在文档中。就绪
,如下所示:
$(函数(){SlideChanger(5)(;})
否则,$(.change\u link”).length
可能会返回0唯一看起来有问题的行是$(.slideshow')。请在控制台IDK中检查更改(索引)
,但您应该将“12票答案”标记为已接受答案