div+css实现三维立方体旋转动画效果代码
代码语言:html
所属分类:动画
代码描述:div+css实现三维立方体旋转动画效果代码,悬浮立方体会变色,立方体是线框的。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @property --time { syntax: "<angle>"; initial-value: 0deg; inherits: false; } @keyframes anim { 0% { --time: 0deg; } 100% { --time: 359deg; } } @property --hover { syntax: "<number>"; initial-value: 0; inherits: false; } @keyframes hover { 0% { --hover: 0; } 100% { --hover: 1; } } @keyframes hover-out { 0% { --hover: 1; } 100% { --hover: 0; } } html { background: black; } .wrapper { position: fixed; width: 960px; height: 960px; left: 50%; top: 50%; margin-left: -480px; margin-top: -480px; perspective: 500px; display: grid; place-items: center; } .box { position: absolute; width: var(--size); height: var(--size); margin-top: calc(var(--size) * -0.5); margin-left: calc(var(--size) * -0.5); transform-style: preserve-3d; animation: anim linear 24s infinite, hover-out linear 0s forwards; transform: translateZ(var(--z-offset)) rotateX(calc((var(--time) + var(--time-offset)) * var(--x-speed))) rotateY(calc((var(--time) + var(--time-offset)) * var(--y-speed))) scale(calc(1 + sin(var(--hover) * 3.14 * 2) * 0.1)); --hover: 1; } .box:hover { animation: anim linear 24s infinite, hover linear 0.3s forwards; } .box:hover * { filter: invert(1); } .box * { position: absolute; top: 0; left: 0; width: var(--size); height: var(--size); box-sizing: border-box; background: linear-gradient(to right, white 3%, black 3% 97%, white 97% 100%); background-size: var(--bg-size) var(--bg-size); } .box *:after { position: absolute; display: block; content: " "; width: 100%; height: 100%; background: linear-gradient(to bottom, white 3%, black 3% 97%, white 97% 100%); background-size: var(--bg-size) var(--bg-size); mix-blend-mode: screen; } .box .top { transform: translateY(calc(var(--size) * -0.5)) rotateX(90deg); } .box .bottom { transform: translateY(calc(var(--size) * 0.5)) rotateX(-90deg); } .box .left { transform: translateX(calc(var(--size) * -0.5)) rotateY(-90deg); } .box .right { transform: translateX(calc(var(--size) * 0.5)) rotateY(90deg); } .box .front { transform: translateZ(calc(var(--size) * 0.5)) rotateY(0deg); } .box .rear { transform: translateZ(calc(var(--size) * -0.5)) rotateY(180deg); } .box-0 { top: 80%; left: 80%; --size: 70.........完整代码请登录后点击上方下载按钮下载查看
网友评论0