iDangerous Swiper plugin fade div on active slide and fade out on swipe

给你一囗甜甜゛ 提交于 2019-12-12 01:25:21

问题


I am trying to setup swiper so that it fades in a div on each slide.

The slides would look like this

<div class="swiper-slide">
            <img src="http://fpoimg.com/300x200?text=Promotion&bg_color=e6e6e6&text_color=ffffff" class="animated fadeInUp"/>
            <div class="card-actions">
            Form field<br>
            Button
            </div>
        </div>

I want it to slide as normal but fade in the div with the class card-actions for each slide when it is the active slide and then when you start to slide to next slide i want it to fade out. Anyone have any idea how to do this?


回答1:


You need to use callbacks for that, for example (jQuery should be included):

var swiper = new Swiper('.swiper-container', {
  onSlideChangeEnd: function (swiper) {
    $('.swiper-slide').each(function () {
        if ($(this).index() === swiper.activeIndex) {
            // Fadein in active slide
            $(this).find('.card-actions').fadeIn(300);
        }
        else {
            // Fadeout in inactive slides
            $(this).find('.card-actions').fadeOut(300);   
        }
    });
  }
});



回答2:


Why don't you modify the Swiper Effect Parameter to fade as effect:fade. For more options visit their Api Documentation.



来源:https://stackoverflow.com/questions/29591076/idangerous-swiper-plugin-fade-div-on-active-slide-and-fade-out-on-swipe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!