CSS: carousel & precedence of translate & rotate
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> body { perspective: 500px; } section { position: relative; width: 200px; height: 100px; margin: 200px auto; transform-style: preserve-3d; transform: rotateX(-25deg); } section div { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: url(/images/pig.jpg) no-repeat; } /* 先translate, 后rotate */ /* div:nth-child(1) { transform: translateZ(100px); } div:nth-child(2) { transform: translateX(100px) rotateY(90deg); } div:nth-child(3) { transform: translateZ(-100px) rotateY(180deg); } div:nth-child(4) { transform: translateX(-100px) rotateY(270deg); } */ /* 先rotate, 后translate */ div:nth-child(1) { transform: translateZ(100px); } div:nth-child(2) { transform: rotateY(90deg) translateZ(100px); } div:nth-child(3) { transform: rotateY(180deg) translateZ(100px); } div:nth-child(4) { transform: rotateY(270deg) translateZ(100px); } </style> </head> <body> <section> <div></div> <div></div> <div></div> <div></div> </section> </body> </html>
Carousel:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> body { /* perspective 小到一定程度,视角会进入carousel内部 */ perspective: 800px; } section { position: relative; width: 200px; height: 300px; margin: 200px auto; font-size: 50px; line-height: 300px; text-align: center; color: aliceblue; transform-style: preserve-3d; /* transform: rotateX(-25deg); */ animation-name: carousel; animation-duration: 3s; animation-timing-function: linear; animation-iteration-count: infinite; } section:hover { animation-play-state: paused; } section div { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: url(/images/pig.jpg) no-repeat; } @keyframes carousel { 0% { transform: rotateY(0); } 100% { transform: rotateY(360deg); } } div:nth-child(1) { transform: translateZ(300px); } div:nth-child(2) { transform: rotateY(45deg) translateZ(300px); } div:nth-child(3) { transform: rotateY(90deg) translateZ(300px); } div:nth-child(4) { transform: rotateY(135deg) translateZ(300px); } div:nth-child(5) { transform: rotateY(180deg) translateZ(300px); } div:nth-child(6) { transform: rotateY(225deg) translateZ(300px); } div:nth-child(7) { transform: rotateY(270deg) translateZ(300px); } div:nth-child(8) { transform: rotateY(315deg) translateZ(300px); } </style> </head> <body> <section> <div>0001</div> <div>0002</div> <div>0003</div> <div>0004</div> <div>0005</div> <div>0006</div> <div>0007</div> <div>0008</div> </section> </body> </html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律