gsap实现烟花棒燃烧四射发光动画效果代码
代码语言:html
所属分类:动画
代码描述:gsap实现烟花棒燃烧四射发光动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body { margin: 0; background: #130f40; background-image: radial-gradient(circle at center, #130f40 0, #0b0926 100%); overflow: hidden; height: 100vh; display: flex; justify-content: center; align-items: center; } .canvas { position: fixed; inset: 0; } .sparkler { stroke-linecap: round; transform-box: fill-box; transform-origin: 50% 50%; } .sparkler__base { stroke: #bbb; stroke-width: 5; } .sparkler__center { fill: rgba(246, 229, 141, 0.075); filter: drop-shadow(0 0 15px #f0932b); } .sparkler__head { filter: drop-shadow(0 0 20px #ffbe76); } .sparkler__line { stroke-width: 1.15; stroke: white; filter: drop-shadow(0 0 5px #f9ca24); } .sparkler__star { fill: #f6e58d; filter: drop-shadow(0 0 8px #f9ca24); stroke: 0; } </style> </head> <body translate="no"> <svg class="canvas" width="100%" height="100%" viewBox="0 0 1600 800"> </svg> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.12.5.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/DrawSVGPlugin3.min.js"></script> <script > (function () { const element = document.querySelector(".neon__light"); const svg = document.querySelector("svg"); let mouse = { x: 0, y: 0 }; let screen = { w: window.innerWidth, h: window.innerHeight }; let wrapper; updateViewBox(); drawSparkler(); let mouseStored = Object.assign({}, mouse); gsap.set(element, { transformOrigin: "${size}0% ${size}0%" }); // Set event listeners window.addEventListener("mousemove", function (e) { setMouseCoords(e); }); window.addEventListener("resize", function (e) { updateVariables(e); }); // And use the ticker to update the SVG gsap.ticker.add(animate); function updateVariables(event) { screen = { w: window.innerWidth, h: window.innerHeight }; updateViewBox(); } function updateViewBox() { svg.setAttribute("viewBox", `0 0 ${screen.w} ${screen.h}`); } function setMouseCoords(event) { mouse.x = event.clientX; mouse.y = event.clientY; } function animate() { if (mouseStored.x === mouse.x && mouseStored.y === mouse.y) return; let xPercent = getPercentage(mouse.x, screen.w) - 50; let yPercent = getPercentage(mouse.y, screen.h) - 50; // mouse animation here gsap.to(wrapper, { ease: "linear", yPercent: yPercent * 0.75, x: xPercent * 0.75, rotation: -xPercent * Math.abs(yPercent) * 0.01 }); // Store the mouse position for the next tick mouseStored.x = mouse.x; mouseStored.y = mouse.y; } function drawSparkler() { let h = screen.h * 0.2; let offsetY = ((screen.h - h) / 2) * 1.2; let sparkW = h * 0.3; let density = 25; wrapper = document.createElementNS("http://www.w3.org/2000/svg", "g"); wrapper.classList.add("sparkler"); let base = document.createElementNS("http://www.w3.org/2000/svg", "path"); base.classList.add("sparkler__base"); base.setAttribute("d", `M ${screen.w / 2} ${offsetY} v ${h}`); let center = document.createElementNS( "http://www.w3.org/2000/svg", "circle" .........完整代码请登录后点击上方下载按钮下载查看
网友评论0