蜂窝扩散动画效果
代码语言:html
所属分类:动画
代码描述:蜂窝扩散动画效果
代码标签: 效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> body { margin: 0; width: 100%; height: 100vh; display: flex; } .hero__background { position: relative; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; margin: auto; font-size: 1.75vw; background: #310E08; } .hex { position: absolute; height: 24.8px; width: 28px; transition: all 0.3s; top: 50%; left: 50%; margin-left: -16px; margin-top: -16px; } </style> </head> <body translate="no"> <div class="hero__background" tabindex="-1"></div> <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/gsap.3.3.1.js"></script> <script > window.onload = (() => { const grid = {}; const ringCount = 33; // Hex SVG const svg = ` <svg class="hex-svg" fill="#310E08" viewbox="0 0 200 174"> <path class="hex-border" d="M0 86.60254037844386L50 0L150 0L200 86.60254037844386L150 173.20508075688772L50 173.20508075688772Z"> </path> </svg> `; function createHex({ className = "hex-not-yet", ring, ...style }) { const hexNode = document.createElement("div"); hexNode.classList.add("hex"); hexNode.classList.add(className); hexNode.classList.add(`hex-ring-${ring}`); hexNode.innerHTML = svg; Object.keys(style).forEach(rule => (hexNode.style[rule] = style[rule])); return hexNode; } function addHexes() { const fragment = document.createDocumentFragment(); // directional motion values const down = { x: 0, y: 28 }; const up = { x: 0, y: -28 }; const upAndRight = { x: 24, y: -14 }; const upAndLeft = { x: -24, y: -14 }; // ring level 0 fragment.appendChild(createHex({ className: "hex-center", ring: 0 })); // concentric rings for (let ring = 1; ring < ringCount; ring++) { // will traverse only half the hexagon (/2) for (let hexagon = 0, prevHexagon; hexagon <= (ring * 6) / 2; hexagon++) { const styles = {}; styles.ring = ring; if (hexagon === 0) { // first hexagon const pos = { x: 0, y: ring * down.y }; prevHexagon = pos; styles.transform = `translate(${pos.x}px, ${pos.y}px)`; styles.className = "hex-bottom"; fragment.appendChild(createHex(styles)); } else if (hexagon === (ring * 6) / 2) { // last traversed hexagon const pos = { x: 0, y: ring * up.y }; prevHexagon = pos; styles.transform = `translate(${pos.x}px, ${pos.y}px)`; styles.className = "hex-top"; fragment.appendChild(createHex(styles)); } else if (hexagon <= ring) { // first sixth of hexagon const pos = { x: prevHexagon.x + upAndRight.x, y: prevHexagon.y + upAndRight.y }; prevHexagon = pos; const mirrorStyles = { ...styles }; styles.className = "hex-bottom-right"; mirrorStyles.className = "hex-bottom-left"; styles.transform = `translate(${pos.x}px, ${pos.y}px)`; mirrorStyles.transform = `translate(-${pos.x}px, ${pos.y}px)`; fragment.appendChild(createHex(styles)); fragment.appendChild(createHex(mirrorStyles)); } else if (hexagon <= ring * 2) { // second sixth of hexagon const mirrorStyles = { ...styles }; const pos = { x: prevHexagon.x + up.x, y: prevHexagon.y + up.y }; prevHexagon = pos; if (hexagon < ring * 2) { styles.className = "hex-right"; mirrorStyles.className = "hex-left"; } else { styles.className = "hex-top-right"; mirrorStyles.className = "hex-top-left"; } styles.transform = `translate(${pos.x}px, ${pos.y}px)`; mirrorStyles.transform = `translate(${-1 * pos.x}px, ${pos.y}px)`; fragment.appendChild(createHex(styles)); fragment.appendChild(createHex(mirrorStyles)); } else { // third sixth of hexagon const pos = { x: prevHexagon.x + upAndLeft.x, y: pre.........完整代码请登录后点击上方下载按钮下载查看
网友评论0