动画效果

(1)animation-name:指定动画名称
(2)animation-duration:设置动画总耗时
(3)animation-iteration-count:设置动画播放次数
(4)animation-direction:alternate //设置交替动画
(5)animation-delay:设置动画延迟
(6)animation-fill-mode:forward|backward|both //设置动画结束时的状态
(7)animation-timing-function:设置动画速率
(8)animation-play-state:paused|running //设置动画播放状态 

创建动画:@keyframes + 动画名字
格式: 
@keyframes moveTest{
     from(0%){
         //添加样式 
    }
    50%{
        //添加样式 
    } 
    to(100%){
        //添加样式 
    }

百分比是指整个动画耗时的百分比 

综合代码演示

<!DOCTYPE html>
<html>
	<head>
		<title>立方体</title>
		<meta charset="utf-8" />
	</head>
	<style>
		#content{
			margin: 200px auto;
			height: 200px;
			width: 200px;
			position: relative;
		}
		#box{
			height: 200px;
			width: 200px;
			position: relative;
			transform: rotate3d(1,1,0,-30deg);
			transform-style: preserve-3d;
			animation-name: Rotate;
			animation-duration: 5s;
			animation-iteration-count: infinite;
			animation-direction: alternate;
			animation-timing-function: linear;
			animation-play-state:paused;
		}
		@keyframes Rotate{
			from{
				transform: rotate3d(1,1,1,30deg);
			}
			to{
				transform: rotate3d(1,1,1,330deg);
			}
		}
		#box > div{
			height: 200px;
			width: 200px;
			opacity: 0.4;
			position: absolute;
			transition: transform 3s;
			border: 1px solid darkblue;
			background-color: black;
		}
		#top{
			transform: translateY(-100px) rotateX(-90deg);
		}
		#bottom{
			transform: translateY(100px) rotateX(90deg);
		}
		#left{
			transform: translateX(-100px) rotateY(-90deg);
		}
		#right{
			transform: translateX(100px) rotateY(90deg);
		}
		#front{
			transform: translateZ(100px);
		}
		#back{
			transform: translateZ(-100px) rotateY(180deg);
		}
		#box:hover > div{
			border: 0px solid darkblue;
		}
		#box:hover #top{
			transform: translateY(-200px) rotateX(-90deg);
		}
		#box:hover #bottom{
			transform: translateY(200px) rotateX(90deg);
		}
		#box:hover #left{
			transform: translateX(-200px) rotateY(-90deg);
		}
		#box:hover #right{
			transform: translateX(200px) rotateY(90deg);
		}
		#box:hover #front{
			transform: translateZ(200px);
		}
		#box:hover #back{
			transform: translateZ(-200px) rotateY(180deg);
		}
		button{
			height: 30px;
			width:60px;
			margin: 15px;
			margin-top: 100px;
		}
		p{
			position: absolute;
			right: -150%;
			top:50%;
		}
	</style>
	<body>
		<div id="content">
			<div id="box">
				<div id="top" class="dire"></div>
				<div id="bottom" class="dire"></div>
				<div id="left" class="dire"></div>
				<div id="right" class="dire"></div>
				<div id="front" class="dire"></div>
				<div id="back" class="dire"></div><br/>
			</div>
			<button id="play">旋转</button>
			<button id="pause">停止</button>
			<p>颜色选择:<input type="color" id="color" /></p>
		</div>
	</body>
	<script>
		document.querySelector('#play').onclick=function(){
			var box=document.querySelector('#box');
			box.style.animationPlayState="running";
		}
		document.querySelector('#pause').onclick=function(){
			var box=document.querySelector('#box');
			box.style.animationPlayState="paused";
		}
		document.querySelector('#color').onchange=function(){
			var color=document.querySelector('#color');
			var dire=document.querySelectorAll('.dire');
			for(var i=0;i<dire.length;i++){
				dire[i].style.backgroundColor=color.value;
			}
		}
	</script>
</html>

效果截图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值