滑块 jQuery 类直到太晚才应用

slider jquery class not being applied until too late

本文关键字:应用 jQuery 滑块      更新时间:2023-09-26

所以简单地把...使用向右箭头转到下一张幻灯片的简单滑块,它应该立即应用一个名为 BounceInUp ....它这样做,但直到大约 1 秒后,你有静态文本,然后效果,我只想从幻灯片开始获得文本效果,...似乎没有什么可以纠正这个问题...

我认为这可能与过渡结束有关,直到下一张幻灯片才真正结束,所以在想可能是按钮本身的点击事件,但我不确定该怎么做......

无论如何,这是一个JSFIDDLE在这里输入链接描述

这是jquery,(所有内容都包含在小提琴中)

主要的jquery代码

$(document).ready(function() {
    //Store a ref to slides
    var $slides = $(".slides");
    //Bind event to the contianed that gets animated
    $(".slide-container")
    .on("transitionend webkitTransitionEnd oTransitionEnd msTransitionEnd", function(e){
        // Remove classes from all the elements within the active container that starts with the class 'add-anim'
        $slides.find(".slide-container [class^='add-anin']").removeClass("animated bounceInUp");
        //Add appropriate classes to the matched elements within the active container
        var $radio = $slides.find(":radio[name='radio-btn']:checked");
        $radio.next(".slide-container").find(".add-anim-up").addClass("animated bounceInUp");
        $radio.next(".slide-container").find(".add-anim-up-late").addClass("animated bounceInUp");
        $radio.next(".slide-container").find(".add-anim-left").addClass("animated bounceInLeft");
    });
});

按钮单击事件位于其位置。

你需要按照你想要的方式设置它,但我认为它可以做到你想要的。

小提琴:http://jsfiddle.net/3hr4ua79/

$(document).ready(function() {
  $('.sp').first().addClass('active');
  $('.sp').hide();
  $('.active').show();
  $('#button-next').click(function() {
    $('.active').removeClass('active animated bounceInUp').addClass('oldActive');
    if ($('.oldActive').is(':last-child')) {
      $('.sp').first().addClass('active animated bounceInUp');
    } else {
      $('.oldActive').next().addClass('active animated bounceInUp');
    }
    $('.oldActive').removeClass('oldActive');
    $('.sp').fadeOut();
    $('.active').fadeIn();
  });
  $('#button-previous').click(function() {
    $('.active').removeClass('active animated bounceInUp').addClass('oldActive');
    if ($('.oldActive').is(':first-child')) {
      $('.sp').last().addClass('active animated bounceInUp');
    } else {
      $('.oldActive').prev().addClass('active animated bounceInUp');
    }
    $('.oldActive').removeClass('oldActive');
    $('.sp').fadeOut();
    $('.active').fadeIn();
  });
});
#slider-wrapper {
  width: 100%;
  height: 200px;
}
#slider {
  width: 100%;
  height: 200px;
  position: relative;
}
.sp {
  width: 100%;
  height: 200px;
  position: absolute;
}
#nav {
  margin-top: 20px;
  width: 100%;
}
#button-previous {
  position: relative;
  top: -100px;
}
#button-next {
  position: relative;
  top: -100px;
  float: right;
}
body {
  overflow: hidden;
}
.animated {
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}
@-webkit-keyframes bounceInUp {
  0%, 60%, 75%, 90%, 100% {
    -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
    animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
  }
  0% {
    opacity: 0;
    -webkit-transform: translate3d(0, 3000px, 0);
    transform: translate3d(0, 3000px, 0);
  }
  60% {
    opacity: 1;
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
  }
  75% {
    -webkit-transform: translate3d(0, 10px, 0);
    transform: translate3d(0, 10px, 0);
  }
  90% {
    -webkit-transform: translate3d(0, -5px, 0);
    transform: translate3d(0, -5px, 0);
  }
  100% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }
}
@keyframes bounceInUp {
  0%, 60%, 75%, 90%, 100% {
    -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
    animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
  }
  0% {
    opacity: 0;
    -webkit-transform: translate3d(0, 3000px, 0);
    transform: translate3d(0, 3000px, 0);
  }
  60% {
    opacity: 1;
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
  }
  75% {
    -webkit-transform: translate3d(0, 10px, 0);
    transform: translate3d(0, 10px, 0);
  }
  90% {
    -webkit-transform: translate3d(0, -5px, 0);
    transform: translate3d(0, -5px, 0);
  }
  100% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }
}
.bounceInUp {
  -webkit-animation-name: bounceInUp;
  animation-name: bounceInUp;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="slider-wrapper">
  <div id="slider">
    <div class="sp" style="background: blue;">akjdfalfkdj</div>
    <div class="sp" style="background: yellow;">akjdfautlfkdkjkhkj</div>
    <div class="sp" style="background: green;">akjdfalfkdiyukjkhkj</div>
    <div class="sp" style="background: red;">akjdfalfkdkkljjkhkj</div>
  </div>
</div>
<div id="nav"></div>
<input type="button" id="button-previous" value="Previous">
<input type="button" id="button-next" value="Next">