gsap实现南瓜头显示动画效果代码
代码语言:html
所属分类:动画
代码描述:gsap实现南瓜头显示动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body { display: flex; justify-content: center; align-items: center; background-color: #000; } #glow { filter: blur(20px); } #shadow { filter: blur(20px); } polygon, rect, circle { opacity: 0; } </style> </head> <body translate="no"> <div id="pumpkin"></div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.11.0.js"></script> <script > const elementSize = 100; function createPumpkin() { const pumpkinDiv = document.getElementById("pumpkin"); const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); svg.setAttribute("width", "600"); svg.setAttribute("height", "600"); pumpkinDiv.appendChild(svg); // Create Geometric Shapes function createShape(type, id) { const element = document.createElementNS("http://www.w3.org/2000/svg", type); element.setAttribute("id", id); const centerX = svg.clientWidth / 2; const centerY = svg.clientHeight / 2; if (type === "rect") { element.setAttribute("width", elementSize); element.setAttribute("height", elementSize); element.setAttribute("x", centerX); element.setAttribute("y", centerY); } else if (type === "circle") { element.setAttribute("cx", centerX); element.setAttribute("cy", centerY); element.setAttribute("r", elementSize); } else if (type === "polygon") { const points = []; for (let i = 0; i < 3; i++) { const angle = (i * 120 * Math.PI) / 180; points.push(centerX + elementSize * Math.cos(angle)); points.push(centerY + elementSize * Math.sin(angle)); } element.setAttribute("points", points.join(" ")); } element.setAttribute("fill", "#F27405"); svg.appendChild(element); } createShape("circle", "glow"); createShape("circle", "shadow"); createShape("polygon", "hat"); for (let i = 0; i < 3; i++) { createShape("circle", `pumpkin${i + 1}`); } for (let i = 0; i < 4; i++) { createShape("polygon", `eye${i + 1}`); } for (let i = 0; i < 10; i++) { createShape("rect", `mouth${i + 1}`); } } createPumpkin(); // Animate geometric shapes into the form of a pumpkin var tl = gsap.timeline({ defaults: { duration: 0.2, transformOrigin: "50% 50%", ease: "power4.out" } }); tl.to("#glow", { opacity: 0.3, scale: 2 }); tl.to("#pumpkin1", {.........完整代码请登录后点击上方下载按钮下载查看
网友评论0