2017-06-01 107 views
0

我想將滑塊添加到我的網站。我從這個網站獲得:https://bootsnipp.com/snippets/K3Al3滑塊不起作用

我添加了HTML代碼,CSS代碼和Javascript代碼,但滑塊不起作用。

任何人有想法?

這些代碼:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> 

<div id="first-slider"> 
<div id="carousel-example-generic" class="carousel slide carousel-fade"> 
    <!-- 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> 
     <li data-target="#carousel-example-generic" data-slide-to="3"></li> 
    </ol> 
    <!-- Wrapper for slides --> 
    <div class="carousel-inner" role="listbox"> 
     <!-- Item 1 --> 
     <div class="item active slide1"> 
      <div class="row"><div class="container"> 
       <div class="col-md-3 text-right"> 
        <img style="max-width: 200px;" data-animation="animated zoomInLeft" src="http://s20.postimg.org/pfmmo6qj1/window_domain.png"> 
       </div> 
       <div class="col-md-9 text-left"> 
        <h3 data-animation="animated bounceInDown">Add images, or even your logo!</h3> 
        <h4 data-animation="animated bounceInUp">Easily use stunning effects</h4>    
       </div> 
      </div></div> 
     </div> 
     <!-- Item 2 --> 
     <div class="item slide2"> 
      <div class="row"><div class="container"> 
       <div class="col-md-7 text-left"> 
        <h3 data-animation="animated bounceInDown"> 50 animation options A beautiful</h3> 
        <h4 data-animation="animated bounceInUp">Create beautiful slideshows </h4> 
       </div> 
       <div class="col-md-5 text-right"> 
        <img style="max-width: 200px;" data-animation="animated zoomInLeft" src="http://s20.postimg.org/sp11uneml/rack_server_unlock.png"> 
       </div> 
      </div></div> 
     </div> 
     <!-- Item 3 --> 
     <div class="item slide3"> 
      <div class="row"><div class="container"> 
       <div class="col-md-7 text-left"> 
        <h3 data-animation="animated bounceInDown">Simple Bootstrap Carousel</h3> 
        <h4 data-animation="animated bounceInUp">Bootstrap Image Carousel Slider with Animate.css</h4> 
       </div> 
       <div class="col-md-5 text-right"> 
        <img style="max-width: 200px;" data-animation="animated zoomInLeft" src="http://s20.postimg.org/eq8xvxeq5/globe_network.png"> 
       </div>  
      </div></div> 
     </div> 
     <!-- Item 4 --> 
     <div class="item slide4"> 
      <div class="row"><div class="container"> 
       <div class="col-md-7 text-left"> 
        <h3 data-animation="animated bounceInDown">We are creative</h3> 
        <h4 data-animation="animated bounceInUp">Get start your next awesome project</h4> 
       </div> 
       <div class="col-md-5 text-right"> 
        <img style="max-width: 200px;" data-animation="animated zoomInLeft" src="http://s20.postimg.org/9vf8xngel/internet_speed.png"> 
       </div> 
      </div></div> 
     </div> 
     <!-- End Item 4 --> 

    </div> 
    <!-- End Wrapper for slides--> 
    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev"> 
     <i class="fa fa-angle-left"></i><span class="sr-only">Previous</span> 
    </a> 
    <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next"> 
     <i class="fa fa-angle-right"></i><span class="sr-only">Next</span> 
    </a> 
</div> 

(function($) { 

//Function to animate slider captions 
function doAnimations(elems) { 
    //Cache the animationend event in a variable 
    var animEndEv = 'webkitAnimationEnd animationend'; 

    elems.each(function() { 
     var $this = $(this), 
      $animationType = $this.data('animation'); 
     $this.addClass($animationType).one(animEndEv, function() { 
      $this.removeClass($animationType); 
     }); 
    }); 
} 

//Variables on page load 
var $myCarousel = $('#next'), 
    $firstAnimatingElems = $myCarousel.find('.item:first').find("[data-animation ^= 'animated']"); 

//Initialize carousel 
$myCarousel.carousel(); 

//Animate captions in first slide on page load 
doAnimations($firstAnimatingElems); 

//Pause carousel 
$myCarousel.carousel('pause'); 


//Other slides to be animated on carousel slide event 
$myCarousel.on('slide.bs.carousel', function (e) { 
    var $animatingElems = $(e.relatedTarget).find("[data-animation ^= 'animated']"); 
    doAnimations($animatingElems); 
}); 
$('#carousel-example-generic').carousel({ 
    interval:3000, 
    pause: "false" 
}); 

})(jQuery); 
+0

你在瀏覽器的控制檯中看到什麼錯誤? – j08691

+1

我假設你可能忘記包含JQuery庫,因爲該插件使用JQuery,你在控制檯中得到了什麼? – Jorden1337

+0

瀏覽器中沒有錯誤。我添加了JQery庫。我添加了一個提醒JavaScript代碼的工作,但滑塊代碼不起作用 – Emre

回答

1

我認爲jQuery是在你的代碼中缺少。您可以在腳本之前包含任何jQuery庫。使用下面的CDN庫和引導庫。

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css"> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> 
<link rel="stylesheet" href="http://cdn.bootcss.com/animate.css/3.5.1/animate.min.css"> 
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script> 
<script src="//netdna.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> 
+0

我添加它,但它沒有工作。 – Emre

+0

另外添加Bootstrap庫 – AdhershMNair

+0

非常感謝。它的工作..你是非常聰明和善良的人,我試圖讓它正確的2-3小時...謝謝 – Emre

0

使用這些頭

<!-- headers for https://bootsnipp.com --><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"><link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css"><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"><link rel="stylesheet" href="http://cdn.bootcss.com/animate.css/3.5.1/animate.min.css"><script src="https:////code.jquery.com/jquery-1.11.0.min.js"></script><script src="https:////netdna.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"</script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>