jquery - 向带进度条的 jquery slider 添加暂停、下一个和上一个按钮

标签 jquery slider

我找到了this simple slider带进度条。它工作正常,但我想添加下一个、上一个和暂停按钮。有人可以帮忙吗?

JS

bar = $('.progress_bar');
time = 3000;

function run(){
    bar.width(0);
    bar.fadeIn(500,function(){
        bar.animate({'width': "100%"}, time).fadeOut(500,function(){
            change();run();
        });
    });
}
$("#slideshow > li:gt(0)").hide();


var change = function() { 
  $('#slideshow > li:first')
    .fadeOut(1000)
    .next()
    .fadeIn(1000)
    .end()
    .appendTo('#slideshow');
};

run();

最佳答案

我制作了一个 codepen.io 示例,它解决了暂停和继续功能,我认为这是更具挑战性的部分。接下来,您只需有一个单击事件,该事件将执行原始示例中的change() 函数: http://codepen.io/KAPastor/pen/ezdQPd

<button id="run">RUN</button>  
<button id="pause">PAUSE</button>  
<button id="continue">CONTINUE</button>  

<div class="progress_bar"></div> 

CSS

div.progress_bar {
    position: absolute;
    bottom: 0;
    left: 0;
    background: #6cecc6;
    height: 5px;
    width: 0;
    opacity: 1;
    z-index: 1002;
    width: 100%;
     }

JS:

$(document).ready(function(){

  $('#run').click(function(){
    $('.progress_bar').width(0);
    $('.progress_bar').fadeIn(500,function(){
        $('.progress_bar').animate({'width': "100%"},    3000)
  });
  });

    $('#pause').click(function(){
      $('.progress_bar').clearQueue();
    $('.progress_bar').stop();

  });

  $('#continue').click(function(){
$('.progress_bar').fadeIn(500,function(){
        $('.progress_bar').animate({'width': "100%"},    3000)
     });
  });



})

我知道这是一个简化的解决方案,但我认为它会有帮助! 如果您还有疑问,请告诉我。 -K

关于jquery - 向带进度条的 jquery slider 添加暂停、下一个和上一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37927340/

相关文章:

javascript - onchange html 值返回后 select2 不起作用

javascript - 拖动内部元素时调整父元素的大小。 (jqueryUI 可拖动)

javascript - 如何使用 javascript 将值从变量传递到 .html()

jquery - 如何使用 jQuery 滑动 div 关闭/打开页面

jquery - Nivo slider 仅延迟第一张图像

jquery - 提交表单不会在 jquery ajax 调用中停止

php - 单击时,在更新 MySQL 数据库时隐藏 DIV

javascript - Prev Next 在幻灯片中导航

android - 在 Android 中的 Vertical Slider 中更改屏幕从右到左的方向过渡

javascript - 需要获取当前幻灯片编号 - Basic JQuery Slider