转载至https://www.cnblogs.com/zyrblog/p/11142624.html
一、前言
最初还是在抖音上看到可以使用简单地代码实现炫酷的网页效果的,但是想要找到可以运行的代码还是比较困难的,最近突然想起就在网上汇总了一些这样的代码。
二、3D效果代码
2.1 旋转相册
1 <!doctype html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>旋转相册</title> 6 <style type="text/css"> 7 body,div,p,ul,ol,li,dl,dt,dd,table,tr,td,form,hr,fieldset,h1,h2,h3,h4,h5,h6,img,input{ 8 margin:0; 9 padding:0; 10 } 11 body{ 12 background: black; 13 } 14 .content{ 15 width: 200px; 16 height: 150px; 17 position: relative; 18 margin:200px auto 0; 19 perspective: 1500px; 20 } 21 .box{ 22 width: 200px; 23 height: 150px; 24 transform-style: preserve-3d; 25 transform:rotateX(-30deg); 26 animation:photo 15s linear infinite; 27 } 28 .box:hover{ 29 animation:photo 15s linear infinite paused; 30 } 31 .box img{ 32 width: 200px; 33 height: 150px; 34 position: absolute; 35 left: 0; 36 top: 0; 37 transform-style: preserve-3d; 38 transition: all 1s; 39 } 40 .box img:nth-child(1){ 41 transform:translateZ(280px); 42 } 43 .box img:nth-child(2){ 44 transform:rotateY(40deg) translateZ(280px); 45 } 46 .box img:nth-child(3){ 47 transform:rotateY(80deg) translateZ(280px); 48 } 49 .box img:nth-child(4){ 50 transform:rotateY(120deg) translateZ(280px); 51 } 52 .box img:nth-child(5){ 53 transform:rotateY(160deg) translateZ(280px); 54 } 55 .box img:nth-child(6){ 56 transform:rotateY(200deg) translateZ(280px); 57 } 58 .box img:nth-child(7){ 59 transform:rotateY(240deg) translateZ(280px); 60 } 61 .box img:nth-child(8){ 62 transform:rotateY(280deg) translateZ(280px); 63 } 64 .box img:nth-child(9){ 65 transform:rotateY(320deg) translateZ(280px); 66 } 67 68 .box img:nth-child(1):hover{ 69 transform:translateZ(280px) scale(1.2); 70 } 71 .box img:nth-child(2):hover{ 72 transform:rotateY(40deg) translateZ(280px) scale(1.2); 73 } 74 .box img:nth-child(3):hover{ 75 transform:rotateY(80deg) translateZ(280px) scale(1.2); 76 } 77 .box img:nth-child(4):hover{ 78 transform:rotateY(120deg) translateZ(280px) scale(1.2); 79 } 80 .box img:nth-child(5):hover{ 81 transform:rotateY(160deg) translateZ(280px) scale(1.2); 82 } 83 .box img:nth-child(6):hover{ 84 transform:rotateY(200deg) translateZ(280px) scale(1.2); 85 } 86 .box img:nth-child(7):hover{ 87 transform:rotateY(240deg) translateZ(280px) scale(1.2); 88 } 89 .box img:nth-child(8):hover{ 90 transform:rotateY(280deg) translateZ(280px) scale(1.2); 91 } 92 .box img:nth-child(9):hover{ 93 transform:rotateY(320deg) translateZ(280px) scale(1.2); 94 } 95 96 @keyframes photo{ 97 0%{ 98 transform:rotateX(-30deg) rotateY(0deg); 99 } 100 100%{ 101 transform:rotateX(-30deg) rotateY(360deg); 102 } 103 } 104 </style> 105 </head> 106 <body> 107 <div class="content"> 108 <div class="box"> 109 <img src="images/1.png" alt=""/> 110 <img src="images/2.png" alt=""/> 111 <img src="images/3.png" alt=""/> 112 <img src="images/4.png" alt=""/> 113 <img src="images/5.png" alt=""/> 114 <img src="images/6.png" alt=""/> 115 <img src="images/7.png" alt=""/> 116 <img src="images/8.png" alt=""/> 117 <img src="images/9.png" alt=""/> 118 </div> 119 </div> 120 </body> 121 </html>
2.2 旋转魔方
2.3 旋转立方体相册
css文件:
1 <pre name="code" class="css">*{ 2 padding:0; 3 margin:0; 4 } 5 body{ 6 width:100%; 7 height:100%; 8 background:linear-gradient(darkred 0%,black 100%); 9 } 10 #react{ 11 width: 200px; 12 height:200px; 13 margin: 200px auto; 14 transform-style:preserve-3d; 15 animation:rotate 20s infinite; 16 animation-timing-function: linear; 17 } 18 #react div{ 19 position:absolute; 20 transition: all .4s; 21 } 22 div .out_pic{ 23 width:200px; 24 height:200px; 25 opacity:0.9; 26 } 27 div .in_pic{ 28 width:100px; 29 height:100px; 30 } 31 #react span{ 32 display:block; 33 position:absolute; 34 width:100px; 35 height:100px; 36 top:50px; 37 left:50px; 38 } 39 @keyframes rotate{ 40 from{transform: rotateX(0deg) rotateY(0deg);} 41 to{transform: rotateX(360deg) rotateY(360deg);} 42 } 43 44 45 .out_front{ 46 transform:translateZ(100px); 47 } 48 .out_back{ 49 transform:translateZ(-100px); 50 } 51 .out_left{ 52 transform:rotateY(90deg) translateZ(100px); 53 } 54 .out_right{ 55 transform: rotateY(-90deg) translateZ(100px); 56 } 57 .out_top{ 58 transform:rotateX(90deg) translateZ(100px); 59 } 60 .out_bottom{ 61 transform: rotateX(-90deg) translateZ(100px); 62 } 63 .in_front{ 64 transform:translateZ(50px); 65 } 66 .in_back{ 67 transform:translateZ(-50px); 68 } 69 .in_left{ 70 transform:rotateY(90deg) translateZ(50px); 71 } 72 .in_right{ 73 transform: rotateY(-90deg) translateZ(50px); 74 } 75 .in_top{ 76 transform:rotateX(90deg) translateZ(50px); 77 } 78 .in_bottom{ 79 transform: rotateX(-90deg) translateZ(50px); 80 } 81 82 /*外面的图片散开*/ 83 #react:hover .out_front{ 84 transform:translateZ(200px); 85 } 86 #react:hover .out_back{ 87 transform:translateZ(-200px); 88 } 89 #react:hover .out_left{ 90 transform:rotateY(90deg) translateZ(200px); 91 } 92 #react:hover .out_right{ 93 transform: rotateY(-90deg) translateZ(200px); 94 } 95 #react:hover .out_top{ 96 transform:rotateX(90deg) translateZ(200px); 97 } 98 #react:hover .out_bottom{ 99 transform: rotateX(-90deg) translateZ(200px); 100 } 101 102 103 /*里面的图片散开*/ 104 #react:hover .in_front{ 105 transform:translateZ(100px); 106 } 107 #react:hover .in_back{ 108 transform:translateZ(-100px); 109 } 110 #react:hover .in_left{ 111 transform:rotateY(90deg) translateZ(100px); 112 } 113 #react:hover .in_right{ 114 transform: rotateY(-90deg) translateZ(100px); 115 } 116 #react:hover .in_top{ 117 transform:rotateX(90deg) translateZ(100px); 118 } 119 #react:hover .in_bottom{ 120 transform: rotateX(-90deg) translateZ(100px); 121 } 122 123 @charset "utf-8"; 124 /* CSS Document */
2.4 动态魔方
2.5 二十面体
2.6 3D相册拖拽动画
2.7 旋转相册
2.8 旋转相册
2.9 旋转立方体相册
三、总结
由此可以看出基本上所有的动画都需要依靠一些库函数已经浏览器的渲染能力来实现。
补充
旋转魔方效果相册(测试有部分问题,还未解决)
css代码
@charset"utf-8"; *{ margin: 0; padding: 0; } body{ /*background:url (../img/preview.png);*/ max-width: 100%; min-width: 100%; height: 100%; background-size: cover; background-repeat: no-repeat; background-attachment: fixed; background-size: 100% 100%; position: absolute; margin-left: auto; margin-right: auto; } li{ list-style: none; } .box{ width: 200px; height: 200px; background-size: cover; background-repeat: no-repeat; background-attachment: fixed; background-size: 100% 100%; position: absolute; margin-left: 42%; margin-right: 22%; -webkit-transform-style:preserve-3d; -webkit-transform:rotateX(13deg); -webkit-animation:move 10s linear infinite; } .minbox{ width: 100px; height: 100px; position: absolute; left: 50px; top: 30px; -webkit-transform-style:preserve-3d; } .minbox li{ width: 100px; height: 100px; position: absolute; left:0; top:0; } .minbox li:nth-child(1){ background: url(../img/01.png) no-repeat 0 0; -webkit-transform:translateZ(50px); } .minbox li:nth-child(2){ background: url(../img/02.png) no-repeat 0 0; -webkit-transform:rotateX(180deg)translateZ(50px); } .minbox li:nth-child(3){ background: url(../img/03.png) no-repeat 0 0; -webkit-transform:rotateX(-90deg)translateZ(50px); } .minbox li:nth-child(4){ background: url(../img/04.png) no-repeat 0 0; -webkit-transform:rotateX(90deg)translateZ(50px); } .minbox li:nth-child(5){ background: url(../img/05.png) no-repeat 0 0; -webkit-transform:rotateY(-90deg)translateZ(50px); } .minbox li:nth-child(6){ background: url(../img/06.png) no-repeat 0 0; -webkit-transform:rotateY(90deg)translateZ(50px); } .maxbox li:nth-child(1){ background: url(../img/1.png) no-repeat 0 0; -webkit-transform:translateZ(50px); } .maxbox li:nth-child(2){ background: url(../img/2.png) no-repeat 0 0; -webkit-transform:translateZ(50px); } .maxbox li:nth-child(3){ background: url(../img/3.png) no-repeat 0 0; -webkit-transform:rotateX(-90deg)translateZ(50px); } .maxbox li:nth-child(4){ background: url(../img/4.png) no-repeat 0 0; -webkit-transform:rotateX(90deg)translateZ(50px); } .maxbox li:nth-child(5){ background: url(../img/5.png) no-repeat 0 0; -webkit-transform:rotateY(-90deg)translateZ(50px); } .maxbox li:nth-child(6){ background: url(../img/6.png) no-repeat 0 0; -webkit-transform:rotateY(90deg)translateZ(50px); } .maxbox{ width: 800px; height:400px; position: absolute; left:0; top:-20px; -webkit-transfrom-style:preserve-3d; } .maxbox li{ width: 200px; height: 200px; background: #fff; border: 1px solid #ccc; position: absolute; left: 0; top: 0; opacity: 0.2; -webkit-transition:all 1s ease; } .maxbox li:nth-child(1){ -webkit-transform:translateZ(100px); } .maxbox li:nth-child(2){ -webkit-transform:rotateX(180deg)translateZ(100px); } .maxbox li:nth-child(3){ -webkit-transform:rotateX(-90deg)translateZ(100px); } .maxbox li:nth-child(4){ -webkit-transform:rotateX(90deg)translateZ(100px); } .maxbox li:nth-child(5){ -webkit-transform:rotateY(-90deg)translateZ(100px); } .maxbox li:nth-child(6){ -webkit-transform:rotateY(90deg)translateZ(100px); } .box:hover ol li:nth-child(1){ -webkit-transform:translateZ(300px); width: 400px; height: 400px; opacity: 0.8; left: -100px; top: -100px; } .box:hover ol li:nth-child(2){ -webkit-transform:rotateX(180deg)translateZ(300px); width: 400px; height: 400px; opacity: 0.8; left: -100px; top: -100px; } .box:hover ol li:nth-child(3){ -webkit-transform:rotateX(-90deg)translateZ(300px); width: 400px; height: 400px; opacity: 0.8; left: -100px; top: -100px; } .box:hover ol li:nth-child(4){ -webkit-transform:rotateX(90deg)translateZ(300px); width: 400px; height: 400px; opacity: 0.8; left: -100px; top: -100px; } .box:hover ol li:nth-child(5){ -webkit-transform:rotateY(-90deg)translateZ(300px); width: 400px; height: 400px; opacity: 0.8; left: -100px; top: -100px; } .box:hover ol li:nth-child(6){ -webkit-transform:rotateY(90deg)translateZ(300px); width: 400px; height: 400px; opacity: 0.8; left: -100px; top: -100px; } @keyframes move{ 0%{ -webkit-transform:rotateX(13deg)rotateY(0deg); } 100%{ -webkit-transform:rotateX(13deg)rotateY(360deg); } }
html代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>送给女朋友的相册</title> <link type="text/css" href="css/style.css" rel="stylesheet"/> </head> <body> <div class="box"> <ul class="minbox"> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> </ul> <ol class="maxbox"> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> </ol> </div> </body> </html>