jQuery的滑块 - 进度条(jQuery Slider - Progress Bar)

2019-08-16 15:25发布

类似: 用进度条jQuery的滑块

我有这样的滑块和进度条,但我想同步与“前”和“下一个”按钮和进度条。 所以,当你点击“下一步”进度条从起点开始。

http://jsfiddle.net/aidenguinnip/8rJws/

$(window).load(function(){
var currentIndex = 0;// store current pane index displayed
var ePanes = $('#slider .panel'), // store panes collection
    time   = 3000,
    bar = $('.progress_bar');

function showPane(index){// generic showPane
    // 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();
    // menu selection
    $('.nav li').removeClass('current').eq(currentIndex).addClass('current');
}
// bind ul links
$('.nav li').click(function(ev){showPane($(this).index());});
// bind previous & next links
$('.previous').click(function(){showPane(currentIndex-1);});
$('.next').click(function(){showPane(currentIndex+1);});
// apply start pane
showPane(0);

function run(){
    bar.width(0);
    showPane(currentIndex+1);
    bar.animate({'width': "+=400"}, time, run);
}

run();

});

Answer 1:

干得好...

http://jsfiddle.net/8rJws/1/

我停止的动画和更换幻灯片时的条宽复位到0,然后重新启动动画(见行10)...

bar.stop(true, true).css("width", 0).animate({'width': "+=400"}, time, run);


文章来源: jQuery Slider - Progress Bar