一款利用html5和css3实现的3D滚动特效的教程
程序员文章站
2022-03-13 09:22:59
怎么利用css3和html5制作圆形很正方形的3D滚动特效,今天给大家带来一款html5和css3实现的3D滚动特效。代码很全,不会的朋友可以可以进来学习一下,需要的朋友可以参考下... 15-01-04...
今天给大家带来一款html5和css3实现的3d滚动特效。效果图如下:
实现的代码。
html代码:
xml/html code复制内容到剪贴板
- <div class="container">
- <div class="cube">
- <div class="side side1">
- </div>
- <div class="side side2">
- </div>
- <div class="side side3">
- </div>
- <div class="side side4">
- </div>
- <div class="side side5">
- </div>
- <div class="side side6">
- </div>
- </div>
- </div>
- <div class="container container2">
- <div class="cube">
- <div class="side side1">
- </div>
- <div class="side side2">
- </div>
- <div class="side side3">
- </div>
- <div class="side side4">
- </div>
- <div class="side side5">
- </div>
- <div class="side side6">
- </div>
- </div>
- </div>
css3代码:
css code复制内容到剪贴板
- body{
- height:100vh;
- }
- .container{
- position:absolute;
- height:100px;
- width:100px;
- left:33%;
- top:50%;
- -webkit-transform: translatex(-50%) translatey(-50%);
- transform: translatex(-50%) translatey(-50%);
- -webkit-perspective:400px;
- perspective:400px;
- }
- .cube{
- height:100px;
- widht:100px;
- -webkit-transform-origin:50% 50%;
- transform-origin:50% 50%;
- -webkit-transform-style:preserve-3d;
- transform-style:preserve-3d;
- -webkit-animation:rotate 4s infinite ease-in-out;
- animation:rotate 4s infinite ease-in-out;
- }
- .side{
- position:absolute;
- display:block;
- height:100px;
- width:100px;
- }
- .side1{
- background:#41c3ac;
- -webkit-transform:translatez(100px);
- transform:translatez(100px);
- }
- .side2{
- background:#ff884d;
- -webkit-transform:rotatey(90deg) translatez(100px);
- transform:rotatey(90deg) translatez(100px);
- }
- .side3{
- background:#32526e;
- -webkit-transform:rotatey(180deg) translatez(100px);
- transform:rotatey(180deg) translatez(100px);
- }
- .side4{
- background:#65a2c5;
- -webkit-transform:rotatey(-90deg) translatez(100px);
- transform:rotatey(-90deg) translatez(100px);
- }
- .side5{
- background:#ffcc5c;
- -webkit-transform:rotatex(90deg) translatez(100px);
- transform:rotatex(90deg) translatez(100px);
- }
- .side6{
- background:#ff6b57;
- -webkit-transform:rotatex(-90deg) translatez(100px);
- transform:rotatex(-90deg) translatez(100px);
- }
- @-webkit-keyframes rotate{
- 0%{
- -webkit-transform:rotatex(0deg) rotatey(0deg) rotatez(0deg);
- }
- 33.33%{
- -webkit-transform:rotatex(360deg) rotatey(0deg) rotatez(0deg);
- }
- 66.66%{
- -webkit-transform:rotatex(360deg) rotatey(360deg) rotatez(0deg);
- }
- 100%{
- -webkit-transform:rotatex(360deg) rotatey(360deg) rotatez(360deg);
- }
- }
- @keyframes rotate{
- 0%{
- transform:rotatex(0deg) rotatey(0deg);
- }
- 50%{
- transform:rotatex(360deg) rotatey(0deg);
- }
- 100%{
- transform:rotatex(360deg) rotatey(360deg);
- }
- }
- a{
- font-family:helvetica;
- color:#428bca;
- text-align:center;
- display:block;
- }
- .container2{
- left:66%;
- }
- .container2 .side{
- border-radius:50%;
- }