用css3transform做出3D旋转的骰子

这个效果利用了3D旋转平移,主要的注意点是当一个面旋转以后他的xyz轴还得按照以前的xyz轴来做,他的xyz轴并不是开始时吧的xyz轴的方向,他的xyz轴也同时受到了旋转的影响而发生改变。所以可以先平移然后在旋转。


<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			.wrap{perspective: 1000px; width: 1000px; height: 600px; margin: 0 auto;background: orchid;position: relative;}
			.wrap .box{transition: all 1s; transform-style: preserve-3d; position: absolute;left: 35%;top: 35%;width: 200px; height: 200px;background: lawngreen;opacity: 0.7;transform: rotateX(0deg);}
			.box>div{position: absolute;left: 0;top: 0;width: 200px;height: 200px;background: black;}
			
			.box div:nth-child(1){transform: translateZ(100px); transition: all 1s;}
			.box div:nth-child(2){transform: translateZ(-100px);transition: all 1s;}
			.box div:nth-child(3){transform: translateX(100px) rotateY(90deg);transition: all 1s;}
			.box div:nth-child(4){transform: translateX(-100px) rotateY(90deg);transition: all 1s;}
			.box div:nth-child(5){transform: translateY(100px) rotateX(90deg);transition: all 1s;}
			.box div:nth-child(6){transform: translateY(-100px) rotateX(90deg);transition: all 1s;}
			
			.box:hover div:nth-child(1){transform: translateZ(200px);}
			.box:hover div:nth-child(2){transform: translateZ(-200px);}
			.box:hover div:nth-child(3){transform: translateX(200px) rotateY(90deg); }
			.box:hover div:nth-child(4){transform: translateX(-200px) rotateY(90deg); }
			.box:hover div:nth-child(5){transform: translateY(200px) rotateX(90deg); }
			.box:hover div:nth-child(6){transform: translateY(-200px) rotateX(90deg); }
			
			@keyframes move{
				from{transform: rotateX(0deg) rotateZ(0deg);}
				to{transform: rotateX(360deg) rotateZ(360deg);}
			}
			.box{
				animation: move 5s  linear 0s infinite;
				
			}
			
			
			.box span{display: block; background: white; width: 50px; height: 50px; position: absolute;left: 75px;top:75px ;}
			.box span:nth-child(6){transform: translateZ(25px); transition: all 1s;}
			.box span:nth-child(7){transform: translateZ(-25px);transition: all 1s;}
			.box span:nth-child(8){transform: translateX(25px) rotateY(90deg);}
			.box span:nth-child(9){transform: translateX(-25px) rotateY(90deg);}
			.box span:nth-child(10){transform: translateY(25px) rotateX(90deg);}
			.box span:nth-child(11){transform: translateY(-25px) rotateX(90deg);}
			
		</style>
	</head>
	<body>
		
		<div class="wrap">
			<div class="box">
				<div></div>
				<div></div>
				<div></div>
				<div></div>
				<div></div>
				<div></div>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
			</div>
		</div>
		
	</body>
	<script type="text/javascript">
		console.log(localStorage.length)
	</script>
</html>





  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值