bootstrap 轮播图动画效果

本文详细介绍了如何使用HTML5、CSS3和JavaScript创建带有动画效果的轮播图组件,包括图片切换、按钮动画及指示器的实现方法。通过实战案例,读者将学会如何为轮播图添加平滑过渡和吸引眼球的动画,提升用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<div id="myCarousel" class="carousel slide" data-ride="carousel">
	<!-- 轮播(Carousel)指标 -->
	<ol class="carousel-indicators">
	<c:forEach var="item"  items="${model}" varStatus="go">
	<c:if test="${go.count==1}">
		<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
	</c:if>
	<c:if test="${go.count!=1}">
		<li data-target="#myCarousel" data-slide-to="${go.count}"></li>
	</c:if>
		
	</c:forEach>
	</ol>   
	<!-- 轮播(Carousel)项目 -->
	<div class="carousel-inner"  role="listbox">
		<c:forEach var="i" items="${model}" varStatus="go">
		<c:if test="${go.count==1}">
			<div class="item active">
			<img src="${i.imgurl}" alt="${i.description}" >
			<div class="carousel-caption">
			<h3 data-animation="animated bounceInLeft">
			This is the caption for slide 1
			</h3>
			<h3 data-animation="animated bounceInRight">
			This is the caption for slide 1
			</h3>
			<button class="btn btn-primary btn-lg"
			data-animation="animated zoomInUp">Button</button>
			</div>
			</div>
		</c:if>
		<c:if test="${go.count!=1}">
			<div class="item">
			<img src="${i.imgurl}" alt="${i.description}" >
			<!-- 添加动画效果animated ,动画循环infinite -->
			<div class="carousel-caption animated rotateIn">
			
			<h3 class="icon-container" data-animation="animated bounceInDown">
			<span class="glyphicon glyphicon-heart"></span>
			</h3>
			<h3 data-animation="animated bounceInUp">
			This is the caption for slide 2
			</h3>
			<button class="btn btn-primary btn-lg"
			data-animation="animated zoomInRight">Button</button>
			</div>
		</div>
		</c:if>
			
		</c:forEach>
		
	</div>
	<!-- 轮播(Carousel)导航 -->
	<a class="left carousel-control" href="#myCarousel" 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="#myCarousel" role="button" data-slide="next">
		<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
		<span class="sr-only">Next</span>
	</a>
	
	</div>
<script type="text/javascript">
var $myCarousel = $('#myCarousel');
$myCarousel.carousel();
function doAnimations(elems) {
	var animEndEv = 'webkitAnimationEnd animationend';
	elems.each(function () {
		var $this = $(this),
		$animationType = $this.data('animation');
		$this.addClass($animationType).one(animEndEv, function () {
			$this.removeClass($animationType);
		})
	})
}

var $firstAnimatingElems = $myCarousel.find('.item:first')
.find('[data-animation ^= "animated"]');
doAnimations($firstAnimatingElems);
$myCarousel.carousel('pause');

$myCarousel.on('slide.bs.carousel', function (e) {
	var $animatingElems = $(e.relatedTarget)
	.find("[data-animation ^= 'animated']");
	doAnimations($animatingElems);
})
</script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值