如何向幻灯片或 nivoslider 等滑块添加进度条(时间轴)

发布于 2025-01-01 01:50:10 字数 4036 浏览 0 评论 0原文

我想向 JavaScript 幻灯片添加进度条(例如 SlidesJS 或 Nivoslider)。

我发现这个问题,它涵盖了我需要的一些内容,但我无法将其集成到我的幻灯片。

这是我所追求的示例。

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

这是我到目前为止的代码:

<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();
});

I want to add a progress bar to a JavaScript slideshow (like SlidesJS or Nivoslider).

I found this question, which covers some of what I need, but I can;t intergrate it into my slideshow.

Here is an example of what I'm after.

For example, when I focus the slideshow (or click pause button), timeline and slider will be paused, and I can resume (when I move out).

Here is the code I have so far:

<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();
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌能量女王 2025-01-08 01:50:10

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

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

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

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

there are a couple different ways you can do this but from a high level here is what I would do:

Every single one of these types of slideshows whether you make it or not uses basically a setInterval function and you are clearing the timer or pausing it when you mouse over. So you have access to a variable someplace within the function that specifies the number of milliseconds you want each slide to show before it moves on and the setInterval fires a function that moves to the next slide. I would access this variable and then use it to drive the jquery rotate plugin which you can micro control the rotation of using the milliseconds in the slider function.

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

If you want a progress bar style like the one in your example you would basically need to convert the number of milliseconds for each slide into a percentage something like: (current / total milliseconds) * 100 and then apply that as the percentage width on the progress bar to make it look like it's animating across.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文