0
我有一个简单的滑块,可以正常工作,但在第一秒钟内,也许页面加载,它会变得混乱,很奇怪。页面加载滑块jquery出现问题
JQUERY
var currentIndex = 0;// store current pane index displayed
var ePanes = $('#slider li'), // store panes collection
time = 3000,
bar = $('.progress_bar');
function showPane(index){// generic showPane
// reset bar
bar.stop(true, true).css("width", 0).animate({'width': "100%"}, time, run);
// hide current pane
ePanes.eq(currentIndex).stop(true, true).fadeOut();
// set current index : check in panes collection length
currentIndex = index;
if(currentIndex < 0) currentIndex = ePanes.length-1;
else if(currentIndex >= ePanes.length) currentIndex = 0;
// display pane
ePanes.eq(currentIndex).stop(true, true).fadeIn();
}
// apply start pane
showPane(0);
function run(){
bar.width(0);
showPane(currentIndex+1);
bar.animate({'width': "100%"}, time, run);
}
run();
TNKS,但增加了一个延迟滑块,不能我们只是展示,而第一张幻灯片还在加载其他幻灯片? – user1765661
@ user1765661是的,这就是为什么我提到“相应调整了'jQuery'”。只需从头开始在'ul#slider'中加载第一个'li',或者使用CSS伪类来定位第一个'li'。例如,'ul#slider li:first-child {display:block; }' – RhapX