gpt4 book ai didi

javascript - 动画标题 Bootstrap 3 轮播

转载 作者:太空宇宙 更新时间:2023-11-04 12:16:46 25 4
gpt4 key购买 nike

我正在寻找一种为 Bootstrap 3 旋转木马的标题制作动画的好方法。我找到了这篇文章Bootstrap carousel-caption animation .

遗憾的是它不起作用,因为它在 fiddle 中工作。在我的页面上,动画并不是真正的动画。标题突然出现并且没有飞入。此外,动画每张图片只能工作一次。因此,在轮播的第二轮中,字幕不再显示。

我的 CSS 是:

.carousel-caption {
z-index: 0;
font-size:24px;
right: 0;
bottom: 0;
left: 0;
top: 0;
padding-bottom: 30px;
padding-top:25%;
height: 100% !important;
background:rgba(0, 0, 0, 0.25);
display: none;
}

我的JS:

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

function toggleCaption() {
$('.carousel-caption').hide();
var caption = carouselContainer.find('.active').find('.carousel-caption');
caption.delay(500).toggle("slide", {direction:'right'});
}


carouselContainer.carousel({
interval: slideInterval,
cycle: true,
pause: "hover"
}).on('slid.bs.carousel', function() {
toggleCaption();
});

可以看到站点here

最佳答案

我遇到了同样的问题,终于找到了解决方案!

我只是 Jquery 的新手,所以我相信您可以解决这个问题。此外,可能最好使用您自己的 Carousal Structure,并且只使用 2 个类来制作您想要动画的字幕。

诀窍是使用 Animate.css,但您必须在动画字幕上禁用 Firefox 的 Ease 功能,否则会导致问题。

在这里 fiddle :http://jsfiddle.net/z6xq12bh/4/

更多动画效果:http://daneden.github.io/animate.css/

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">
<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;
}

关于javascript - 动画标题 Bootstrap 3 轮播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28648205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com