CSS

十、3D&动画

1. 兔斯基


<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			
			*{
				margin: 0;
				padding: 0;
			}
			html,body{
				height: 100%;
				overflow: hidden;
			}
			#tsj{
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translate3d(-50%,-50%,0);
				width: 48px;
				height: 48px;
				background: url(img/animation.png) no-repeat;
				background-position:0 0;
				animation: move 1s steps(12,end) infinite ;
			}
			
			@keyframes move{
				from{
					background-position: 0 0;
				}
				to{
					background-position:-576px 0;
				}
			}
		</style>
	</head>
	<body>
		<div id="tsj">
			
		</div>
	</body>
</html>

2. 开机动画(2d)


<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			html,body{
				height: 100%;
				overflow: hidden;
			}
			#wrap{
				height: 100%;
				position: relative;
				background: gray;
			}
			#wrap > .inner{
				text-align: center;
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translate3d(-50%,-50%,0);
				white-space: nowrap;
			}
			#wrap > .inner >span{
				position: relative;
				/*animation: move 1s linear infinite alternate;*/
			}
			
			@keyframes move{
				from{
					top: 0px;
				}
				to{
					top: -10px;
				}
			}
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="inner">
				<span></span>
				<span></span>
				<span></span>
				<span></span>
				<span>S</span>
				<span>Y</span>
				<span>F</span>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		
		window.onload=function(){
			var spanNodes = document.querySelectorAll("#wrap > .inner >span");
			var colors=["red","orange","yellow","green","blue","pink","deeppink","red","orange","yellow","green","blue","pink","deeppink","#1883BA"];
			for(var i=0;i<spanNodes.length;i++){
				spanNodes[i].style.animation="move .3s "+(i*50)+"ms linear infinite alternate";
				spanNodes[i].style.color=colors[i];
			}
		}
		
		
		
	</script>
</html>

3. 开机动画(3d)


<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			html,body{
				height: 100%;
				overflow: hidden;
			}
			#wrap{
				height: 100%;
				position: relative;
				background: pink;
				perspective: 200px;
			}
			#wrap > .inner{
				height: 100%;
				position: relative;
				transform-style: preserve-3d;
			}
			@keyframes move{
				from{
					transform: translate3d(-50%,-50%,0) rotateY(0deg);
				}
				to{
					transform: translate3d(-50%,-50%,0) rotateY(360deg);
				}
			}
			
			#wrap > .inner > img{
				width: 30%;
				margin-top: -38px;
				animation: move 2s linear infinite ;
			}
			#wrap > .inner > img,#wrap > .inner > p{
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translate3d(-50%,-50%,0) rotateY(0deg);
			}
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="inner">
				<img src="img/load/logo2.png"  />
				<p>已加载0%</p>
			</div>
		</div>
	</body>
	<script src="js/data.js"></script>
	<script type="text/javascript">
		window.onload=function(){
			var pNode = document.querySelector("#wrap > .inner > p");
			var flag = 0;
			var arr=[];
			for(item in imgData){
				arr=arr.concat(imgData[item]);
			}
			
			for(var i=0;i<arr.length;i++){
				var img = new Image();
				//ajax请求
				img.src=arr[i];
				img.onload=function(){
					flag++;
					pNode.innerHTML="已加载"+(Math.round(flag/arr.length*100))+"%";
				}
				img.onerror=function(){
					console.log("地址有问题")
				}
			}
			
		}
	</script>
</html>

十一、flex

1. new(对比)

(1)容器
① 容器的布局方向
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 400px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:flex;
				flex-direction: column;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

② 容器的排列方向
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 400px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:flex;
				flex-direction: row-reverse;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

③ 富裕空间管理(主轴)
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 400px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:flex;
				flex-direction: row-reverse;
				 /*
				 flex-start                  富裕空间在主轴的正方向
		         flex-end                    富裕空间在主轴的反方向
		         center  	                              富裕空间在主轴的两边
		         space-between               富裕空间在项目之间
		         space-around(box 没有的)    富裕空间在项目两边
		         */
		        justify-content: space-around;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

④ 富裕空间管理(侧轴)
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 400px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:flex;
				flex-direction: row-reverse;
				 /*
				 flex-start                  富裕空间在主轴的正方向
		         flex-end                    富裕空间在主轴的反方向
		         center  	                              富裕空间在主轴的两边
		         space-between               富裕空间在项目之间
		         space-around(box 没有的)    富裕空间在项目两边
		         */
		        justify-content: space-around;
		         /*
		         flex-start: 富裕空间在侧轴的正方向;
		         flex-end: 富裕空间在侧轴的反方向;
		         content: 富裕空间在侧轴的两边;
		         
		         baseline(box 没有的) 按基线对齐
		         stretch(box 没有的)	  等高布局
		         */
		        align-items: stretch;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

(2)项目
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 400px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:flex;
				flex-direction: row-reverse;
				 /*
				 flex-start                  富裕空间在主轴的正方向
		         flex-end                    富裕空间在主轴的反方向
		         center  	                              富裕空间在主轴的两边
		         space-between               富裕空间在项目之间
		         space-around(box 没有的)    富裕空间在项目两边
		         */
		        justify-content: space-around;
		         /*
		         flex-start: 富裕空间在侧轴的正方向;
		         flex-end: 富裕空间在侧轴的反方向;
		         content: 富裕空间在侧轴的两边;
		         
		         baseline(box 没有的) 按基线对齐
		         stretch(box 没有的)	  等高布局
		         */
		        align-items: stretch;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
				flex-grow: 1;
			}
			
			#wrap > .item:nth-child(1){
				flex-grow: 4;
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

2. old(对比)

(1)容器
① 容器的布局方向
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 400px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:-webkit-box;
				/*-webkit-box-orient控制主轴和侧轴分别是哪一根*/
				-webkit-box-orient:vertical;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

② 容器的排列方向
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 400px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:-webkit-box;
				/*-webkit-box-orient控制主轴和侧轴分别是哪一根*/
				-webkit-box-orient:horizontal;
				/*-webkit-box-direction控制主轴方向*/
				-webkit-box-direction: reverse;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

③ 富裕空间管理(主轴)
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 400px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:-webkit-box;
				/*-webkit-box-orient控制主轴和侧轴分别是哪一根*/
				-webkit-box-orient:horizontal;
				/*-webkit-box-direction控制主轴方向*/
				-webkit-box-direction: reverse;
				 /* 
				  start  富裕空间在右边
		          end 	  富裕空间在左边
		          center  富裕空间在两边
		          justify 富裕空间在项目之间
		         */
				-webkit-box-pack: start;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

④ 富裕空间管理(侧轴)
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 400px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:-webkit-box;
				/*-webkit-box-orient控制主轴和侧轴分别是哪一根*/
				-webkit-box-orient:vertical;
				/*-webkit-box-direction控制主轴方向*/
				-webkit-box-direction: reverse;
				 /* 
				  start  富裕空间在右边(x)  下边(y)
		          end 	  富裕空间在左边	(x) 上边(y)
		          center  富裕空间在两边
		          justify 富裕空间在项目之间
		         */
				-webkit-box-pack: justify;
				 /*
				 	start  富裕空间在右边(x)  下边(y)  
          		 	end 	  富裕空间在左边	(x) 上边(y)
           		 	center 	富裕空间在两边
           		 */ 
           		 -webkit-box-align:end;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

(2)项目
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 400px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:-webkit-box;
				/*-webkit-box-orient控制主轴和侧轴分别是哪一根*/
				-webkit-box-orient:vertical;
				/*-webkit-box-direction控制主轴方向*/
				-webkit-box-direction: reverse;
				 /* 
				  start  富裕空间在右边(x)  下边(y)
		          end 	  富裕空间在左边	(x) 上边(y)
		          center  富裕空间在两边
		          justify 富裕空间在项目之间
		         */
				-webkit-box-pack: justify;
				 /*
				 	start  富裕空间在右边(x)  下边(y)  
          		 	end 	  富裕空间在左边	(x) 上边(y)
           		 	center 	富裕空间在两边
           		 */ 
           		 -webkit-box-align:end;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

3. new(add)

(1)容器新增
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 100px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:flex;
				/*flex-direction: row;*/
		        justify-content: flex-start;
		        align-items: flex-start;
		        /*控制侧轴的方向*/
		        /*flex-wrap: wrap-reverse;*/
		        /*多行多列时,富裕空间的管理,会把所有行、列看成一个整体*/
		        /*align-content: flex-end;*/
		        flex-flow:row  wrap-reverse;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
			}
			
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

(2)order&align-self
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 300px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:flex;
				/*flex-direction: row;*/
		        justify-content: flex-start;
		        align-items: flex-start;
		        /*控制侧轴的方向*/
		        /*flex-wrap: wrap-reverse;*/
		        /*多行多列时,富裕空间的管理,会把所有行、列看成一个整体*/
		        /*align-content: flex-end;*/
		        flex-flow:row  nowrap;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
			}
			
			#wrap > .item:nth-child(1){
				order: 3;
				align-self:flex-end;
			}
			#wrap > .item:nth-child(2){
				order: 1;
			}
			#wrap > .item:nth-child(3){
				order: 5;
			}
			#wrap > .item:nth-child(4){
				order: 2;
			}
			#wrap > .item:nth-child(5){
				order: 4;
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

(3)flex-grow&flex-basis
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			/*
				flex-grow
				box-flex 默认值都为0
				
				
				flex-grow: 
					   可用空间 = (容器大小 - 所有相邻项目flex-basis的总和)
					   				400 - 5*50 = 150
					   				400 - 5*0  = 400
					   可扩展空间 = (可用空间/所有相邻项目flex-grow的总和)
					   				150 / 8 = 18.75
					   				400 / 8 = 50
					   每项伸缩大小 = (伸缩基准值 + (可扩展空间 x flex-grow值))
					   				
									50 + 18.75*4 = 125
									50 + 18.75*1 = 68.75
									
									0 + 50*4 = 200
									0 + 50 = 50
				
			*/
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 400px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:flex;
				flex-direction: row;
		        justify-content: flex-start;
		        align-items: flex-start;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
				flex-grow: 1;
				flex-basis: 0;
			}
			
			#wrap > .item:nth-child(1){
				flex-grow: 4;
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

(4)flex-shrink
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			/*
			 * flex-shrink 默认值为1 只有在 flex-wrap:nowrap时才有作用
			 * 
			 * 
			 * flex-shrink:
				   每项flex收缩大小 = 伸展基准值 - (收缩比例 / 收缩比例总和 x 溢出的空间)-->并不是
				   
				   1.计算收缩因子与基准值乘的总和  
				   2.计算收缩因数
				              收缩因数=(项目的收缩因子*项目基准值)/第一步计算总和    
				   3.移除空间的计算
				              移除空间= 项目收缩因数 x 负溢出的空间 
				
			*/
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 100px;
				height: 300px;
				border: 1px solid;
				margin:100px auto;
				display:flex;
				flex-direction: row;
		        justify-content: flex-start;
		        align-items: flex-start;
			}
			#wrap > .item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				line-height: 50px;
			}
			
			#wrap > .item:nth-child(1){
			}
			
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

(5)flex-shrink
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#wrap{
				width: 100px;
				height: 400px;
				border: 1px solid;
				display:flex;
			}
			/*
			 * flex-shrink 默认值为1 只有在 flex-wrap:nowrap时才有作用
			 * 
			 * 
			 * flex-shrink:
				   每项flex收缩大小 = 伸展基准值 - (收缩比例 / 收缩比例总和 x 溢出的空间)-->并不是
				   			
				   				1/5 * 300 = 60;
				   				
				   				200 - 60 = 140
				   				50 - 60 = -10
				   
				   
				   
				   
				   1.计算收缩因子与基准值乘的总和  
				   		200 + 50*4 = 400
				   2.计算收缩因数
				              收缩因数=(项目的收缩因子*项目基准值)/第一步计算总和   
				              1*200 / 400 = 1/2
				              1*50 / 400 = 1/8 
				   3.移除空间的计算
				              移除空间= 项目收缩因数 x 负溢出的空间 
				              1/2*300 = 150
				              1/8*300 = 37.5
				              
				              200 - 150 =50;
				              50 - 37.5 = 12.5
				
			*/
			.item{
				width: 50px;
				height: 50px;
				background: pink;
				text-align: center;
				flex-shrink: 1;
			}
			.item:nth-child(1){
				width: 200px;
			}
		</style>
	</head>
	<body>
		<div id="wrap">
			<div class="item">1</div>
			<div class="item">2</div>
			<div class="item">3</div>
			<div class="item">4</div>
			<div class="item">5</div>
		</div>
	</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值