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>