Bootstrap 动画启动轮播标题

u0njafvf  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(1)|浏览(124)

我想动画的标题Twitters引导旋转木马。在标题中,我得到了一个h1标签和四个h4标签。
我想先淡入h1,然后淡入h4-Tag。在滑动到下一张图片之前,我想先淡出h4-Tag,然后淡出h1-Tag。
我的滑块.js:

$('#carousel-example-generic').on('slide.bs.carousel', function () {
    $("h1").fadeIn(2000);
});

$('#carousel-example-generic').on('slid.bs.carousel', function () {
    $("h1").fadeOut(2000);
});

我的HTML:

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
        <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
        <li data-target="#carousel-example-generic" data-slide-to="1"></li>
        <li data-target="#carousel-example-generic" data-slide-to="2"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
        <div class="item active">
            <img src="http://www.werkart-hannover.de/tl_files/images/projekte/neubau-einfamilienhaus-2.jpg" alt="...">
            <div class="carousel-caption">
                <h1>Here is a test title</h1>
                <h4>Test</h4>
                <h4>Test</h4>
                <h4>Test</h4>
                <h4>Test</h4>
            </div>
        </div>
        <div class="item">
            <img src="http://www.loth-haus.de/galerie/neubau_5232.jpg" alt="...">
            <div class="carousel-caption">
                <h1>Here is a test title</h1>
                <h4>Test</h4>
                <h4>Test</h4>
                <h4>Test</h4>
                <h4>Test</h4>
            </div>
        </div>
        <div class="item">
            <img src="http://www.loth-haus.de/galerie/neubau_5232.jpg" alt="...">
            <div class="carousel-caption">
                <h1>Here is a test title</h1>
                <h4>Test</h4>
                <h4>Test</h4>
                <h4>Test</h4>
                <h4>Test</h4>
            </div>
        </div>
    </div>

    <!-- Controls -->
    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
    </a>
</div>

另一个问题是我的动画只在第二张幻灯片上有效。我怎样才能像我描述的那样使标题内的元素具有动画效果呢?下面是我的小提琴:http://jsfiddle.net/7fh3o32y/

laik7k3q

laik7k3q1#

我也遇到了同样的问题,终于得到了解决方案!
我只是一个Jquery的初学者,所以我相信你可以清理这一点。而且,可能最好使用你自己的Caroal结构,并只使用2类的标题,你想动画。
诀窍是使用Animate.css,但你必须禁用Firefox的动画字幕上的Ease功能,否则会导致问题。
在此处拨弄:http://jsfiddle.net/z6xq12bh/4/
有关更多动画效果:http://daneden.github.io/animate.css/
于飞:

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
      <!-- Indicators -->
      <ol class="carousel-indicators">
        <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
        <li data-target="#carousel-example-generic" data-slide-to="1"></li>
        <li data-target="#carousel-example-generic" data-slide-to="2"></li>
      </ol>

      <!-- Wrapper for slides -->
      <div class="carousel-inner">
        <div class="item active">
          <img src="http://placehold.it/1200x400" alt="...">
          <div class="carousel-caption">
              <h3 class="toggleHeading">Caption Text</h3>
              <p class="toggleCaption">This is some text<p>
          </div>
        </div>
        <div class="item">
          <img src="http://placehold.it/1200x400" alt="...">
          <div class="carousel-caption">
              <h3 class="toggleHeading">Caption Text 2</h3>
               <p class="toggleCaption">This is some text<p>
          </div>
        </div>
        <div class="item">
          <img src="http://placehold.it/1200x400" alt="...">
          <div class="carousel-caption">
              <h3 class="toggleHeading">Caption Text 3</h3>
               <p class="toggleCaption">This is some text<p>
          </div>
        </div>
      </div>

      <!-- Controls -->
      <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left"></span>
      </a>
      <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right"></span>
      </a>
    </div> <!-- Carousel -->

JS:

<script>
    var carouselContainer = $('.carousel');
    var slideInterval = 5000;

        function toggleH(){
            $('.toggleHeading').hide()
            var caption = carouselContainer.find('.active').find('.toggleHeading').addClass('animated fadeInRight').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',
                function (){
                $(this).removeClass('animated fadeInRight')});
        caption.slideToggle();
        }

        function toggleC(){
            $('.toggleCaption').hide()
            var caption = carouselContainer.find('.active').find('.toggleCaption').addClass('animated fadeInUp').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',
                function (){
                $(this).removeClass('animated fadeInUp')
        });
        caption.slideToggle();
        }
    carouselContainer.carousel({
    interval: slideInterval, cycle: true, pause: "hover"})
    .on('slide.bs.carousel slid.bs.carousel', toggleH).trigger('slide.bs.carousel')
    .on('slide.bs.carousel slid.bs.carousel', toggleC).trigger('slide.bs.carousel');
     </script>

CSS:

.toggleHeading {
        animation-delay: 0.5s;
      -webkit-animation-delay: 0.5s;
         -moz-animation-delay: 0.5s;
           -o-animation-delay: 0.5s;
           -moz-transition: none !important;
    }

    .toggleCaption {
        animation-delay: 1.5s;
      -webkit-animation-delay: 1.5s;
         -moz-animation-delay: 1.5s;
           -o-animation-delay: 1.5s;
           -moz-transition: none !important;
    }

相关问题