Java基础、中级、高级、架构面试资料

HTML5 实现3D翻转立方体

HTML5 herman 3299浏览 0评论
公告:“业余草”微信公众号提供免费CSDN下载服务(只下Java资源),关注业余草微信公众号,添加作者微信:xttblog2,发送下载链接帮助你免费下载!
本博客日IP超过2000,PV 3000 左右,急需赞助商。
极客时间所有课程通过我的二维码购买后返现24元微信红包,请加博主新的微信号:xttblog2,之前的微信号好友位已满,备注:返现
受密码保护的文章请关注“业余草”公众号,回复关键字“0”获得密码
所有面试题(java、前端、数据库、springboot等)一网打尽,请关注文末小程序
视频教程免费领
腾讯云】1核2G5M轻量应用服务器50元首年,高性价比,助您轻松上云

我渐渐的迷上了 HTML5 的动画,它总能给我带来很大惊喜。今天继续为大家分享一款使用 HTML5 动画制作的 3D 翻转立方体效果。本文将为大家介绍 HTML5 动画的制作过程。

网上基于 HTML5 的立方体动画有很多,有些是基于 Canvas 的动画特效,比如HTML5 webkit 3D立方体图片旋转滑块。这次要分享的这款HTML5 3D立方体动画比较普通,它可以自己不停的旋转以凸显其3D的魅力。

HTML5 翻转立方体 动画

HTML5 实现3D翻转立方体

上面这张图是该动画运行效果的一个截图。全部实现代码如下:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>HTML5 3D立方体动画|业余草|www.xttblog.com</title>
  <style type="text/css">
	body{ 
  background: #1a1a1a;
  -webkit-perspective: 600px;
}

.cube{
  width: 150px;
  height: 150px;
  position: relative;
  top: 100px;
  left: 50%;
  margin-left: -75px;
  
  -webkit-transform-style: preserve-3d;
  -webkit-transform: rotateY(0deg) translateZ(-200px);
  
  -webkit-animation-name: rotationMainContainer;
  -webkit-animation-duration: 5s;
  -webkit-animation-timing-function: linear;
  -webkit-animation-iteration-count: infinite;
  -webkit-animation-play-state: running;
}

.cube-face{
  width: 150px;
  height: 150px;
  position: absolute;
  opacity: .95;
  background: #ff033e;
  
  -webkit-transform-origin: 50% 50%;
  
  -webkit-animation-duration: 5s;
  -webkit-animation-timing-function: linear;
  -webkit-animation-iteration-count: infinite;
  -webkit-animation-play-state: running;
}

.cube-face-front{
  -webkit-transform: translateZ(75px);
  -webkit-animation-name: bgCAFace;
}

.cube-face-left{
  -webkit-transform: rotateY(90deg) translateZ(75px);
  -webkit-animation-name: bgCALeft;
}

.cube-face-back{
  -webkit-transform: translateZ(-75px);
  -webkit-animation-name: bgCABack;
}

.cube-face-right{
  -webkit-transform: rotateY(90deg) translateZ(-75px);
  -webkit-animation-name: bgCARight;
}

.cube-face-top{
  -webkit-transform: rotateX(90deg) translateZ(-75px);
  -webkit-animation-name: bgCATopBottom;
}

.cube-face-bottom{
  -webkit-transform: rotateX(90deg) translateZ(75px);
  -webkit-animation-name: bgCATopBottom;
}

@-webkit-keyframes rotationMainContainer{
  0%   { -webkit-transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
  100% { -webkit-transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg) }
}

@-webkit-keyframes bgCAFace{
  0%   { background: #7F1041; }
  25%  { background: #FF6DAD; }
  50%  { background: #FF2182; }
  100% { background: #7F3756; }
}

@-webkit-keyframes bgCALeft{
  0% { background: #7F3756; }
  25%   { background: #7F1041; }
  50%  { background: #FF6DAD; }
  100%  { background: #FF2182; }
}

@-webkit-keyframes bgCABack{
  0%  { background: #FF2182; }
  25% { background: #7F3756; }
  50%   { background: #7F1041; }
  100%  { background: #FF6DAD; }
}

@-webkit-keyframes bgCARight{
  0%  { background: #FF6DAD; }
  25%  { background: #FF2182; }
  50% { background: #7F3756; }
  100%   { background: #7F1041; }
}

@-webkit-keyframes bgCATopBottom{
  0%  { background: #7F0E2D; }
  25%  { background: #FF6891; }
  50% { background: #FF1C5A; }
  100%   { background: #7F3449; }
}
  </style>
</head>
<body>
<div style="text-align:center;clear:both;">
<script src="/follow.js" type="text/javascript"></script>
</div>
  <div class="cube">
  <div class="cube-face cube-face-front"></div>
  <div class="cube-face cube-face-left"></div>
  <div class="cube-face cube-face-back"></div>
  <div class="cube-face cube-face-right"></div>
  <div class="cube-face cube-face-top"></div>
  <div class="cube-face cube-face-bottom"></div>
</div>
</body>
</html>

本文没有用到额外的图片,因此就没有共享到百度云盘,希望的鞋童可以自己按照代码思路试一试。

业余草公众号

最后,欢迎关注我的个人微信公众号:业余草(yyucao)!可加作者微信号:xttblog2。备注:“1”,添加博主微信拉你进微信群。备注错误不会同意好友申请。再次感谢您的关注!后续有精彩内容会第一时间发给您!原创文章投稿请发送至532009913@qq.com邮箱。商务合作也可添加作者微信进行联系!

本文原文出处:业余草: » HTML5 实现3D翻转立方体