2014-03-19 48 views
0

由于某些原因,bootstrap不允许我在js中设置间隔时间。为什么我的javascript不会影响bootstrap旋转木马

我正在使用Middleman服务我的静态网站本地主机,我似乎无法让js影响从引导传送带。我装的引导和这样

!!! 
%html 
    %head 
    %title Save Rosie 
    %meta{charset: "utf-8"}/ 
    /Always force latest IE rendering engine or request Chrome Frame 
    %meta{content: "IE=edge,chrome=1", "http-equiv" => "X-UA-Compatible"}/ 
    /Use title if it's in the page YAML frontmatter 
    = stylesheet_link_tag "fonts", "all", "bootstrap" 
    = javascript_include_tag "jquery-1.11.0.min", "all", "bootstrap" 
    %body{class: page_classes} 
    = yield 

我的自定义JS转盘功能齐全

.carousel.slide{ "data-ride" => "carousel" } 
     .carousel-inner 
     .item.active 
      %img{ :src => 'https://s3-us-west-2.amazonaws.com/rosiesdonations/Rosie1.png', :alt => "Rosie Picture one" } 
     .item 
      %img{ :src => 'https://s3-us-west-2.amazonaws.com/rosiesdonations/Rosie2.jpg', :alt => "Rosie Picture two" } 
     .item 
      %img{ :src => 'https://s3-us-west-2.amazonaws.com/rosiesdonations/Rosie3.jpg', :alt => "Rosie Picture three" } 

,但是当我在all.js叫

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

它不会在切换2秒,而是默认值5.

看着有一个错误:Uncaught TypeError:Object [object Object] has没有方法'旋转木马'

我试着首先加载bootstrap,但没有奏效。

+0

是DOM准备好时你设定的时间间隔? – slash197

+0

我怎么知道? – MikaAK

+0

您的代码必须位于'$(document).ready(function(){...您的代码...})块中;' – slash197

回答

2

在您的脚本bootstrap.js必须在all.js之前。

+0

我试过这个,但我得到了同样的东西 – MikaAK

0

我不知道这是否会是一个问题,但要尽量用class="active"设置第一个旋转木马幻灯片项目,然后初始化JS以这种方式旋转木马:

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

试过这个,但我仍然没有被捕获TypeError:Object [object Object] has no method'carousel' – MikaAK

+0

从[here](http:/下载carousel.js /bootstrapdocs.com/v2.0.3/docs/assets/js/bootstrap-carousel.js),然后将其加载到代码中。 –

+0

试过这个,但仍然得到相同的错误 – MikaAK