首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bootstrap Carousel函数参数

问Bootstrap Carousel函数参数
EN

Stack Overflow用户
提问于 2018-01-31 00:49:23
回答 1查看 478关注 0票数 0

我正在学习一篇关于制作引导转盘动画的教程。但是有一点我不明白,那就是元素是如何与我想要动画的每个部分相关的?例如,函数如何知道elems与html中的某个元素相关?

这是教程,以防您需要更多信息https://www.sitepoint.com/bootstrap-carousel-with-css3-animations/

代码语言:javascript
复制
function doAnimations(elems) {
  var animEndEv = 'webkitAnimationEnd animationend';

  elems.each(function () {
    var $this = $(this),
        $animationType = $this.data('animation');

    // Add animate.css classes to
    // the elements to be animated 
    // Remove animate.css classes
    // once the animation event has ended
    $this.addClass($animationType).one(animEndEv, function () {
      $this.removeClass($animationType);
    });
  });
}

// Select the elements to be animated
// in the first slide on page load
var $firstAnimatingElems = $myCarousel.find('.item:first')
                           .find('[data-animation ^= "animated"]');

// Apply the animation using our function
doAnimations($firstAnimatingElems);

// Pause the carousel 
$myCarousel.carousel('pause');

// Attach our doAnimations() function to the
// carousel's slide.bs.carousel event 
$myCarousel.on('slide.bs.carousel', function (e) { 
  // Select the elements to be animated inside the active slide 
  var $animatingElems = $(e.relatedTarget)
                        .find("[data-animation ^= 'animated']");
  doAnimations($animatingElems);
});

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-31 02:25:01

bootstrap的slide.bs.carousel事件才能做到这一点。根据轮播事件上引导程序的document,该事件具有名为relatedTarget的属性,该属性包含作为活动项滑入适当位置的DOM元素。

您的教程将进一步查找具有data-animation属性的元素,并在doAnimations(elems)函数中传递它们。通过使用each事件,可以对存储在elems中的元素逐个执行动画。

教程的代码是为第一张幻灯片手动调用doAnimations,但是对于所有连续的幻灯片,bootstrap的事件会处理它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48526569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档