简体   繁体   English

Hammer.js + CSS Bootstrap轮播:设置自动播放

[英]hammer.js + Css Bootstrap carousel: Set autoplay

Hi I have created a swipeable slider based on Hammer.js and Bootstrap css. 嗨,我已经基于Hammer.js和Bootstrap css创建了可滑动的滑块。 I cannot get the autoplay function to work! 我无法使用自动播放功能! I added a class of active to my first "li", as explained on the css bootstrap website, I added a class to the carousel of ".carousel", and tried adding this at the top of my script below the html content of my body: 我在我的第一个“ li”中添加了一个活动类,如css bootstrap网站上所述,我在“ .carousel”的轮播中添加了一个类,并尝试将其添加到脚本顶部的html内容下方。身体:

$(function(){
$('.carousel').carousel({
  interval: 2000
});
});

I tried it with and without a document ready function, neither worked. 我在有和没有文档就绪功能的情况下都尝试过,但都没有用。

You can see all the scripts here, let me know if you would like to see a JS fiddle. 您可以在这里看到所有脚本,如果您想查看JS小提琴,请告诉我。

http://archibaldbutler.com/projects/PA-consulting/ http://archibaldbutler.com/projects/PA-consulting/

Here is a solution. 这是一个解决方案。 Your carousel library doesn't support autoplaying, so something quick and dirty like this will be good enough to get you started: 您的轮播资料库不支持自动播放,因此像这样的快速和肮脏的东西足以让您入门:

var currentPane = 0;
setTimeout(playSlides, 2000);
function playSlides() {
    currentPane = currentPane + 1;
    if ( currentPane > 5 ) {
        currentPane = 0;
        carousel.showPane(0);
    } else {
        carousel.next();
    }

    setTimeout(playSlides,2000);
}

There is no such thing as jQuery.fn.carousel in your code (on your site), therefore this wont work. 您的代码中(在您的网站上)没有jQuery.fn.carousel这样的东西,因此这行不通。

$('.carousel').carousel({
  interval: 2000
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM