首页 > web前端 > css教程 > 正文

css实现钻石的旋转效果

巴扎黑
发布: 2017-09-11 11:52:58
原创
2204人浏览过

css钻石旋转实现:


<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			/* 钻石旋转 
			 * 要实现这个钻石旋转: 首先需要明确这个钻石分为上下两个部分,上面包含六个正三角形,下面有6个倒三角形
			 * css实现正三角形:上右下左的方向 border-style: solid;border-color:transparent;border-width: 0 50px 170px 50px; border-bottom-color: rgba(255,0,0,0.5)
			 * css实现倒三角形:上右下左的方向 border-style: solid;border-color:transparent;border-width: 170px 50px 0 50px; border-top-color: rgba(255,0,0,0.5)
			 * 然后提供一个3D环境,给外层盒子添加 transform-style: preserve-3d;flat 所有的子元素在2D平面中;preserve-3D 所有的子元素 在3D 平面中
			 * 上面的三角形设置为绝对定位 absolute
			 * 使用css3的transform 三角形按角度转动 排列成钻石的上半部分,同理实现下半部分
			 * rotateY:沿着Y轴实现旋转,translateZ:沿着Z轴移动88px;沿着X轴 旋转31度 
			 * 写一个动画tuoluo 0~50%~100%  沿着z轴旋转
			 * 实现动画的循环播放animation: tuoluo 3s linear infinite; */
			
			
			/*@keysframes*/
			.wrap{
				width: 200px;
				height: 400px;
				margin: 30px auto;
			}
			@keyframes tuoluo{
				0%{
					transform: rotateY(0deg) rotateX(0deg);
				}
				50%{
					transform: rotateY(-180deg) rotateX(18deg);
				}
				100%{
					transform: rotateY(-360deg) rotateX(0deg);
				}
			}
			.wrap .tuoluo{
				width: 100%;
				height: 100%;
				transform-style: preserve-3d; 
				/* flat 所有的子元素在2D平面中*/
				/* preserve-3D 所有的子元素 在3D 平面中*/
				animation: tuoluo 3s linear infinite;
			}
			.wrap .tuoluo .tuoluo-top,
			.wrap .tuoluo .tuoluo-bottom{
				position: relative;
				width: 100%;
				height: 50%;
			}
			.tuoluo-top .face-top{
				position: absolute;
				top: 29px;
				width: 0;
				height: 0;
				border-style: solid;
				border-color: transparent;
				border-width: 0 50px 170px 50px;
				border-bottom-color: rgba(65,92,162,.5);
				/*元素变形基点的位置*/
				transform-origin: center bottom;
			}
			.tuoluo-top .face-top:nth-of-type(1){
				transform: rotateY(0deg) translateZ(88px) rotateX(31deg);
			}
			.tuoluo-top .face-top:nth-of-type(2){
				transform: rotateY(60deg) translateZ(88px) rotateX(31deg);
			}
			.tuoluo-top .face-top:nth-of-type(3){
				transform: rotateY(120deg) translateZ(88px) rotateX(31deg);
			}
			.tuoluo-top .face-top:nth-of-type(4){
				transform: rotateY(180deg) translateZ(88px) rotateX(31deg);
			}
			.tuoluo-top .face-top:nth-of-type(5){
				transform: rotateY(240deg) translateZ(88px) rotateX(31deg);
			}
			.tuoluo-top .face-top:nth-of-type(6){
				transform: rotateY(300deg) translateZ(88px) rotateX(31deg);
			}
			.tuoluo-bottom .face-bottom{
				position: absolute;
				width: 0;
				height: 0;
				border-style: solid;
				border-color: transparent;
				border-width: 170px 50px 0 50px;
				border-top-color: rgba(65,92,162,.5);
				/*元素变形基点的位置*/
				transform-origin: center top;
			}
			.tuoluo-bottom .face-bottom:nth-of-type(1){
				transform: rotateY(0deg) translateZ(88px) rotateX(-31deg);
			}
			.tuoluo-bottom .face-bottom:nth-of-type(2){
				transform: rotateY(60deg) translateZ(88px) rotateX(-31deg);
			}
			.tuoluo-bottom .face-bottom:nth-of-type(3){
				transform: rotateY(120deg) translateZ(88px) rotateX(-31deg);
			}
			.tuoluo-bottom .face-bottom:nth-of-type(4){
				transform: rotateY(180deg) translateZ(88px) rotateX(-31deg);
			}
			.tuoluo-bottom .face-bottom:nth-of-type(5){
				transform: rotateY(240deg) translateZ(88px) rotateX(-31deg);
			}
			.tuoluo-bottom .face-bottom:nth-of-type(6){
				transform: rotateY(300deg) translateZ(88px) rotateX(-31deg);
			}
		</style>
	</head>
	<body>
		<p class="wrap">
			<p class="tuoluo">
				<p class="tuoluo-top">
					<p class="face-top"></p>
					<p class="face-top"></p>
					<p class="face-top"></p>
					<p class="face-top"></p>
					<p class="face-top"></p>
					<p class="face-top"></p>
				</p>
				<p class="tuoluo-bottom">
					<p class="face-bottom"></p>
					<p class="face-bottom"></p>
					<p class="face-bottom"></p>
					<p class="face-bottom"></p>
					<p class="face-bottom"></p>
					<p class="face-bottom"></p>
				</p>
			</p>
		</p>
	</body>
</html>  
登录后复制

以上就是css实现钻石的旋转效果的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
相关标签:
css
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号