切割轮播的前端案例

效果
在这里插入图片描述

代码

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="js/jquery.min.js"></script>
	<style>

		.container{
			position: relative;
			width: 560px;
			height: 300px;
		}
		.container ul{
			/*transform-style:preserve-3d;*/
			/*transform: rotateX(-30deg) rotateY(21deg);*/
			width: 560px;
			height: 300px;
			border:2px solid red;
			list-style-type: none;
			margin:0;
			padding:0;
		}
		.container ul li{
			position: relative;
			float: left;
			/*一张图分作5片,图的总宽度是560*/
			width: 112px;
			height: 300px;
			transform-style:preserve-3d;
			transition:all 0.5s;
		}
		.container ul li span{
			position: absolute;
			left:0;
			top:0;
			width: 100%;
			height: 100%
		}
		/*以下4个选择器设定立体效果*/
		.container ul li span:nth-child(1){
			background: yellow;
			transform:translateZ(150px);
		}
		.container ul li span:nth-child(2){
			background: pink;
			transform:translateY(-150px) rotateX(90deg);
		}
		.container ul li span:nth-child(3){
			background: orange;
			transform:translateZ(-150px) rotateX(180deg);
		}
		.container ul li span:nth-child(4){
			background: blue;
			transform:translateY(150px) rotateX(270deg);
		}
		/*//以下4个选择器设定第n个span的背景图*/
		.container ul li span:nth-child(1){
			background: url(images/1.jpg);
		}
		.container ul li span:nth-child(2){
			background: url(images/2.jpg);
		}
		.container ul li span:nth-child(3){
			background: url(images/3.jpg);
		}
		.container ul li span:nth-child(4){
			background: url(images/4.jpg);
		}
		/*以下5个选择器用于设定第i个li的背景定位*/
		.container ul li:nth-child(1) span{
			background-position: 0px 0px;
		}
		.container ul li:nth-child(2) span{
			background-position: -112px 0px;
		}
		.container ul li:nth-child(3) span{
			background-position: -224px 0px;
		}
		.container ul li:nth-child(4) span{
			background-position: -336px 0px;
		}
		.container ul li:nth-child(5) span{
			background-position: -448px 0px;
		}

		/*.container ul li:nth-child(1) span:nth-child(1){
			background: url(images/1.jpg) 0px 0px;
		}
		.container ul li:nth-child(2) span:nth-child(1){
			background: url(images/1.jpg) -112px 0px;
		}
		.container ul li:nth-child(3) span:nth-child(1){
			background: url(images/1.jpg) -224px 0px;
		}
		.container ul li:nth-child(4) span:nth-child(1){
			background: url(images/1.jpg) -336px 0px;
		}
		.container ul li:nth-child(5) span:nth-child(1){
			background: url(images/1.jpg) -448px 0px;
		}

		.container ul li:nth-child(1) span:nth-child(2){
			background: url(images/2.jpg) 0px 0px;
		}
		.container ul li:nth-child(2) span:nth-child(2){
			background: url(images/2.jpg) -112px 0px;
		}*/
			
		.container span.left, .container span.right{
			position: absolute;
			top:50%;
			background: rgba(0,0,0,0.3);
			width: 18px;
			height: 40px;
			font-size:25px;
			font-weight: bold;
			color:white;
			text-align: center;
			line-height: 40px;
			cursor:pointer;
		}
		.container span.left{
			left:0;
		}
		.container span.right{
			right:0;
		}
	</style>
</head>
<body>
	<div class="container">
		<ul>
			<li>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
			</li>
			<li>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
			</li>
			<li>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
			</li>
			<li>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
			</li>
			<li>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
			</li>
		</ul>
		<span class="left">&lt;</span>
		<span class="right">&gt;</span>
	</div>
</body>
</html>
<script>
	$(function(){
		var allowClick = true;
		var seq = 0;	//代表初始的转动角度次数
		//先给这5个li的动画效果设置不同的延时(delay)
		//index表示循环中的索引号,item表示当前项(这里是li)
		$("ul>li").each(   function(index,item){
			var delay_time = index*0.25;
			$(item).css({"transition-delay": delay_time + "s"});
		}  );

		//transitionend事件:动画结束事件
		$("ul>li:last-child").on('transitionend',function(){
			allowClick = true;		//允许点击
		});

		//
		$("span.left").on('click',function(){
			//如果allowClick为false,表示此时还不允许点击,就直接退出
			if(allowClick == false){ return ;}

			allowClick = false;	//如果可以继续下去,此时就会去执行动画,则此刻
								//就必须讲这个allowClick设定为false
			seq--;
			var angle = -seq*90;
			$("ul>li").css({"transform":"rotateX(" + angle + "deg)"});
		});
		$("span.right").on('click',function(){
			//如果allowClick为false,表示此时还不允许点击,就直接退出
			if(allowClick == false){ return ;}
			allowClick = false;
			seq++;
			var angle = -seq*90;
			$("ul>li").css({"transform":"rotateX(" + angle + "deg)"});
		});
	});
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值