javascript - slider 不起作用

标签 javascript html slider

我正在尝试向我的网站添加 slider 。我从这个网站得到的:https://bootsnipp.com/snippets/K3Al3 .

我添加了 HTML 代码、CSS 代码和 Javascript 代码,但 slider 不起作用。

有人有想法吗?

这些是代码:

<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); 

最佳答案

我认为您的代码中缺少 jQuery。您可以在脚本之前包含任何 jQuery 库。使用下面的 CDN 库和 Bootstrap 库。

<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>

关于javascript - slider 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44313050/

相关文章:

css - Slider Revolution,减少移动设备上的左边距/填充

javascript - 如何在 Bxslider 中让新幻灯片覆盖上一张幻灯片?

javascript - Crm字段控制命令Javascript

javascript - 使用javascript拆分字符串

JavaScript - 将选定的下拉列表值传递给方法

JavaScript 设置图像/元素源/属性未更新图像/元素

html - 如何创建媒体规则以水平居中绝对 div?

javascript - 使用 lodash 根据两个不同数组的数据过滤数组

html - iPhone 上的网站宽度

javascript - tmpl 未定义 jquery.slider.js