内容简介:Slick 是个网页轮播组件 https://github.com/kenwheeler/slickAnimate.css是一个css3动画库https://github.com/daneden/animate.css两者常结合使用,能达到比较好的效果。
Slick 是个网页轮播组件 https://github.com/kenwheeler/slick
Animate.css是一个css3动画库https://github.com/daneden/animate.css
两者常结合使用,能达到比较好的效果。
但是 Slick slider 用 animate.css动画时,第一个slider动画不起作用的问题,可以用以下方法解决!
html代码:
<div id="hero-slider"> <div class="hero-slide" style="background-image: url('http://lorempixel.com/1920/500/abstract/1');"> <div class="container"> <div class="row hero-content text-center"> <div class="col-sm-6"> <img src="//placehold.it/720x320" class="img-responsive slide-message" data-animation="fadeInLeftBig" data-delay="0.5s" /> <a href="#" class="btn btn-primary" data-animation="fadeInUpBig" data-delay="1s">LEARN MORE</a> </div> <div class="col-sm-6 hidden-xs"> <img src="//placehold.it/540x320" class="img-responsive" data-animation="fadeInRightBig" data-delay="0.5s" /> </div> </div> </div> </div> <div class="hero-slide" style="background-image: url('http://lorempixel.com/1920/500/abstract/3');"> <div class="container"> <div class="row hero-content text-center"> <div class="col-sm-6"> <img src="//placehold.it/720x320" class="img-responsive slide-message" data-animation="fadeInRight" data-delay="0.5s" /> <a href="#" class="btn btn-primary" data-animation="fadeInUp" data-delay="1s">LEARN MORE</a> </div> <div class="col-sm-6 hidden-xs"> <img src="//placehold.it/540x320" class="img-responsive" data-animation="fadeInLeft" data-delay="0.5s" /> </div> </div> </div> </div> <div class="hero-slide" style="background-image: url('http://lorempixel.com/1920/500/abstract/8');"> <div class="container"> <div class="row hero-content text-center"> <div class="col-sm-6"> <img src="//placehold.it/720x320" class="img-responsive slide-message" data-animation="rotateIn" data-delay="0.5s" /> <a href="#" class="btn btn-primary" data-animation="bounceIn" data-delay="1.5s">LEARN MORE</a> </div> <div class="col-sm-6 hidden-xs"> <img src="//placehold.it/540x320" class="img-responsive" data-animation="rollIn" data-delay="0.5s" /> </div> </div> </div> </div> </div>
css代码:
body { padding-top: 50px; } .slick-prev { left: 5px; z-index:9999; } .slick-next { right: 5px; } .slick-dots { bottom: -10px; } .hero-slide { background-size: cover; background-position: center bottom; background-repeat: no-repeat; } .hero-content { height: 400px; display: table-cell; vertical-align: middle; } .slide-message { margin-bottom: 20px; } @media (min-width: 992px) { .hero-content { height: 500px; } }
js代码:
$(document).ready(function() { $('#hero-slider').on('init', function(e, slick) { var $firstAnimatingElements = $('div.hero-slide:first-child').find('[data-animation]'); doAnimations($firstAnimatingElements); }); $('#hero-slider').on('beforeChange', function(e, slick, currentSlide, nextSlide) { var $animatingElements = $('div.hero-slide[data-slick-index="' + nextSlide + '"]').find('[data-animation]'); doAnimations($animatingElements); }); $('#hero-slider').slick({ autoplay: true, autoplaySpeed: 10000, dots: true, fade: true }); function doAnimations(elements) { var animationEndEvents = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend'; elements.each(function() { var $this = $(this); var $animationDelay = $this.data('delay'); var $animationType = 'animated ' + $this.data('animation'); $this.css({ 'animation-delay': $animationDelay, '-webkit-animation-delay': $animationDelay }); $this.addClass($animationType).one(animationEndEvents, function() { $this.removeClass($animationType); }); }); } });
演示地址 https://codepen.io/anon/pen/YbyZOm
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 图解词法作用域与作用域链
- javascript作用域之块级作用域
- javascript静态作用域和动态作用域
- JavaScript系列之作用域和作用域链
- 【7】JavaScript 函数高级——作用域与作用域链
- 深入学习js之——词法作用域和动态作用域
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。