2014-04-19 71 views
0

我試圖實施一個引導程序傳送帶。它不會因爲某種原因滑動...當我點擊箭頭滑動我的http://localhost:3000/http://localhost:3000/#carousel-example-genericBootstrap Carousel(如何加載JavaScript?)

我相信我缺少必要的JavaScript要求,但不確定如何包括它們。

他們去哪個文件? application.jsapplication.css.scss或在我的views之一?

另外需要包含哪些代碼,它是否必須在頁面的特定位置?是bootstrap.js還是bootstrap-transition.js還有其他什麼?我真的迷失了。

這是我的旋轉木馬,我相信這是正確的:

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> 
    <!-- Indicators --> 
    <ol class="carousel-indicators"> 
    <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li> 
    <li data-target="#carousel-example-generic" data-slide-to="1"></li> 
    <li data-target="#carousel-example-generic" data-slide-to="2"></li> 
    </ol> 

    <!-- Wrapper for slides --> 
    <div class="carousel-inner"> 

    <div class="item active"> 
     <%= link_to image_tag("closeup.jpg", alt: "image", class:'img-responsive') %> 
     <div class="carousel-caption"> 
     ... 
     </div> 
    </div> 

    <div class="item"> 
     <%= link_to image_tag("parksolar.jpg", alt: "image", class:'img-responsive') %> 
     <div class="carousel-caption"> 
     ... 
     </div> 
    </div> 

    <div class="item"> 
     <%= link_to image_tag("big1.jpg", alt: "image", class:'img-responsive') %> 
     <div class="carousel-caption"> 
     ... 
     </div> 
    </div> 

    </div> 

    <!-- Controls --> 
    <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"> 
    <span class="glyphicon glyphicon-chevron-left"></span> 
    </a> 
    <a class="right carousel-control" href="#carousel-example-generic" data-slide="next"> 
    <span class="glyphicon glyphicon-chevron-right"></span> 
    </a> 
</div> 

這是我apllication.js

// This is a manifest file that'll be compiled into application.js, which will include all the files 
// listed below. 
// 
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 
// 
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 
// compiled file. 
// 
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details 
// about supported directives. 
// 
// bootstrap.js 
// Loads all Bootstrap javascripts 
//= require bootstrap 
//= require jquery 
//= require jquery_ujs 
//= require turbolinks 
//= require_tree . 

這是我application.css.scss(請注意,我也有一個navbar,sass標記可能會影響我的傳送帶滑塊嗎?)

@import "bootstrap"; 

.navbar { 
    border-radius: 0px; 
    border-width: 0px; 
    font-size: 16px; 
    font-weight: bold; 
    color: #f0ad4e; 
    padding-left: 150px; 
    padding-right: 150px; 
    padding-top: 35px; 
    margin: 0px; 
    background:transparent; 
} 

.navbar-default .navbar-nav > li > a { 
    color: white; 
} 

.navbar-default .navbar-brand { 
    color: white; 
} 






/* 
* This is a manifest file that'll be compiled into application.css, which will include all the files 
* listed below. 
* 
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 
* 
* You're free to add application-wide styles to this file and they'll appear at the top of the 
* compiled file, but it's generally better to create a new file per style scope. 
* 
* 
*= require_self 
*= require_tree . 
*/ 

使用檢查元素我發現這些錯誤:

enter image description here

它們意味着什麼?

+0

使用鉻檢查器(f12)並轉到網絡選項卡,檢查所有文件正在加載,如果沒有檢查此問題http://stackoverflow.com/questions/15811889/my-rails-javascript-manifest- file-both-compiles-nor-include-any-required-file,它可能會幫助 – Zagen

+0

正在加載文件 – user3408293

+0

您提供的鏈接沒有答案。我正在使用rails 4. – user3408293

回答

2

我想和大家分享,我已經解決了很多的「不使用Javascript工作」的問題簡單地通過具有

//= require jquery 
//= require jquery_ujs 

上述

//= require bootstrap 
中的application.js文件

請試試這個,讓我知道它是否有幫助。 你可以在這裏分享你的GEM文件內容嗎?

+0

這工作!你是個天才!爲什麼這是必要的? – user3408293

+1

它應該在所有對jQuery有很強依賴性的文件之上,而不僅僅是bootstrap。這些文件試圖在甚至加載之前使用jQuery,這就是爲什麼必要.Btw @Ritikesh好眼睛;) – Zagen

+0

謝謝你們,請記住這一點。 – user3408293