简体   繁体   English

仅在首次加载页面时在第一张幻灯片上添加课程

[英]Add class only on first slide the first time the page loads

I have implemented a slideshow using Bootstrap Carousel. 我已经使用Bootstrap Carousel实现了幻灯片放映。 As you guys might now, this carousel is pretty basic so I wanted to add some eye candy to it. 你们现在可能已经知道,这种旋转木马非常基本,所以我想在上面添加一些糖果。

Using the animate.css transitions, I wanted to only animate the first slide. 使用animate.css过渡,我只想动画第一张幻灯片。 I tried 我试过了

$('.caption-wrapper').addClass('scrollpoint sp-effect3');

setTimeout(function () { 

$('.caption-wrapper').removeClass('scrollpoint sp-effect3 animated fadeInDown');

}, 2000);

and it works! 而且有效! However, as you can see, I am adding and removing a class using the setTimeout function (which is kind of weird). 但是,正如您所看到的,我正在使用setTimeout函数添加和删除一个类(有点奇怪)。

Is there a cleaner way to do this? 有没有更清洁的方法可以做到这一点?

So basically, as mentioned by @isherwoord, I used Bootstrap carousel available events, in this case the "slide" event. 因此,基本上,如@isherwoord所述,我使用了Bootstrap轮播可用事件,在本例中为“ slide”事件。 Here's the answer: 答案是:

$('#slideshow').on('slide.bs.carousel', function () {

  $('.caption-wrapper').removeClass('scrollpoint sp-effect3 animated fadeInDown');

});

This a lot more elegant solution to what I originally had. 这比我原来的解决方案优雅得多。

Are you looking for something like this: 您是否正在寻找这样的东西:

$(document).ready(function() {
  function slider(){
       $('.caption-wrapper').addClass('scrollpoint sp-effect3',function(){
       setTimeout(function () { 
           $('.caption-wrapper').removeClass('scrollpoint sp-effect3 animated fadeInDown');
           }, 2000);
       });
   }
  setInterval(slider,3000);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM