【问题标题】:How to add progress bar (timeline) to slider like slides or nivoslider如何将进度条(时间线)添加到幻灯片或 nivoslider 等滑块
【发布时间】:2012-02-23 20:10:45
【问题描述】:

我想为 JavaScript 幻灯片添加一个进度条(如 SlidesJS 或 Nivoslider)。

我找到了this question,它涵盖了我需要的一些内容,但我无法将其集成到我的幻灯片中。

Here is an example of what I'm after.

例如,当我聚焦幻灯片(或单击暂停按钮)时,时间轴和滑块将暂停,我可以恢复(当我移出时)。

这是我目前的代码:

<div id="products_example">
    <div id="products">
        <div id="slides_timeline"></div>
        <div class="slides_container">
            <a href="http://www.zappos.com/pro-keds-royal-plus-lo-grey" target="_blank"><img src="img/1144953-3-2x.jpg" width="366" alt="1144953 3 2x"></a>
            <a href="http://www.zappos.com/pro-keds-royal-plus-lo-grey" target="_blank"><img src="img/1144953-1-2x.jpg" width="366" alt="1144953 1 2x"></a>
            <a href="http://www.zappos.com/pro-keds-royal-plus-lo-grey" target="_blank"><img src="img/1144953-2-2x.jpg" width="366" alt="1144953 2 2x"></a>
            <a href="http://www.zappos.com/pro-keds-royal-plus-lo-grey" target="_blank"><img src="img/1144953-4-2x.jpg" width="366" alt="1144953 4 2x"></a>
            <a href="http://www.zappos.com/pro-keds-royal-plus-lo-grey" target="_blank"><img src="img/1144953-5-2x.jpg" width="366" alt="1144953 5 2x"></a>
            <a href="http://www.zappos.com/pro-keds-royal-plus-lo-grey" target="_blank"><img src="img/1144953-6-2x.jpg" width="366" alt="1144953 6 2x"></a>
            <a href="http://www.zappos.com/pro-keds-royal-plus-lo-grey" target="_blank"><img src="img/1144953-p-2x.jpg" width="366" alt="1144953 P 2x"></a>
        </div>
        <ul class="pagination">
            <li><a href="#"><img src="img/1144953-3-2x.jpg" width="55" alt="1144953 3 2x"></a></li>
            <li><a href="#"><img src="img/1144953-1-2x.jpg" width="55" alt="1144953 1 2x"></a></li>
            <li><a href="#"><img src="img/1144953-2-2x.jpg" width="55" alt="1144953 2 2x"></a></li>
            <li><a href="#"><img src="img/1144953-4-2x.jpg" width="55" alt="1144953 4 2x"></a></li>
            <li><a href="#"><img src="img/1144953-5-2x.jpg" width="55" alt="1144953 5 2x"></a></li>
            <li><a href="#"><img src="img/1144953-6-2x.jpg" width="55" alt="1144953 6 2x"></a></li>
            <li><a href="#"><img src="img/1144953-p-2x.jpg" width="55" alt="1144953 P 2x"></a></li>
        </ul>
    </div>
</div>
$(function(){
    $('#products').slides({
        preload: true,
        preloadImage: 'img/loading.gif',
        effect: 'fade',
        slideSpeed:300,
        crossFade:true,
        fadeSpeed: 500,
        generateNextPrev: true,
        generatePagination: false,              
        play: 5000,
        hoverPause:true,
        animationStart: function(){animateTimeline();}, // Function called at the start of animation
        animationComplete: function(){}, // Function called at the completion of animation
        slidesLoaded: function() {} // Function is called when slides is fully loaded
    });
});

////reset timeline
function resetTimeline(){
    var timeline = $("#slides_timeline");
    timeline.css({width:'0'},0);
}

////animate timeline
function animateTimeline(){
    var timeline = $("#slides_timeline");
    timeline.stop().css({width:'0',opacity:1},0);
    timeline.stop().animate({width:'100%'},5000,'linear',function(){$(this).animate({opacity:0,width:0})});
}

$("#products .next,.pagination li a").click(function(){
    resetTimeline();
});

【问题讨论】:

    标签: jquery progress-bar slideshow timeline


    【解决方案1】:

    有几种不同的方法可以做到这一点,但从高层次来看,我会这样做:

    这些类型的幻灯片中的每一种,无论您是否制作,基本上都使用 setInterval 函数,并且您正在清除计时器或在鼠标悬停时暂停它。因此,您可以在函数中的某个位置访问一个变量,该变量指定您希望每张幻灯片在继续移动之前显示的毫秒数,并且 setInterval 会触发一个移动到下一张幻灯片的函数。我会访问这个变量,然后用它来驱动 jquery rotate 插件,您可以在滑块函数中使用毫秒来微控制旋转。

    https://code.google.com/p/jqueryrotate/

    如果您想要像示例中那样的进度条样式,您基本上需要将每张幻灯片的毫秒数转换为百分比,例如:(当前/总毫秒)* 100,然后将其应用为百分比进度条上的宽度,使其看起来像动画一样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-28
      • 2019-01-01
      • 1970-01-01
      • 2020-11-25
      • 2022-09-25
      • 2014-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多