js实现可拖拽三维立方体内圆环旋转动画效果代码
代码语言:html
所属分类:三维
代码描述:js实现可拖拽三维立方体内圆环旋转动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> :root { --cube: 50vmin; } *, *::before, *::after { box-sizing: border-box; } body { margin: 0; } #cube-wrap { perspective: 1000px; perspective-origin: 50% var(--cube); height: 100vh; display: grid; align-content: center; background: black; overflow: hidden; cursor: grab; } #cube-wrap:active { cursor: grabbing; } .cube { position: relative; width: var(--cube); height: var(--cube); transform-style: preserve-3d; transform: rotateX(-30deg) rotateY(45deg); margin: 0 auto; user-select: none; } .inner-wrap { position: relative; width: var(--cube); height: var(--cube); transform-style: preserve-3d; animation: spin 5s infinite linear; margin: 0 auto; user-select: none; } .cube .face { position: absolute; background: rgba(255, 0, 150, 0.25); width: 100%; height: 100%; backface-visibility: hidden; border: 3px solid black; } .front { transform: rotateY(0deg) translateZ(calc(var(--cube) * 0.5)); } .back { transform: rotateY(180deg) translateZ(calc(var(--cube) * 0.5)); } .left { transform: rotateY(-90deg) translateZ(calc(var(--cube) * 0.5)); } .right { transform: rotateY(90deg) translateZ(calc(var(--cube) * 0.5)); } .top { transform: rotateX(90deg) translateY(calc(var(--cube) * -0.5)); transform-origin: top left; } .bottom { transform: rotateX(-90deg) translateY(calc(var(--cube) * 0.5)); transform-origin: bottom left; } .inner1 { transform: rotateX(0) rotateY(90deg) translateY(0px); } .inner2 { transform: rotateX(90deg) translateY(0px); } .inner3 { } .cube .inner { border: 6px solid black; backface-visibility: visible !important; border-radius: 100%; } /*.inner::after { content: ""; position: absolute; width: 50%; height: 50%; top: 0; left: 0; border-bottom: 5px solid black; } .inner::before { content: ""; position: absolute; width: 50%; height: 50%; bottom: 0; right: 0; border-left: 5px solid black; }*/ @keyframes spin { from { transform: rotateX(0) rotateY(0); } to { transform: rotateX(1turn) rotateY(1turn); } } </style>.........完整代码请登录后点击上方下载按钮下载查看
网友评论0