gsap实现插上彩灯插座亮灯动画效果代码
代码语言:html
所属分类:拖放
代码描述:gsap实现插上彩灯插座亮灯动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body { margin: 0; padding: 0; background-color: #969393; height: 100vh; overflow: hidden; } svg { width: 100%; height: 100%; max-height: 100%; max-width: 100%; animation: fade-in forwards 0.3s 0.8s; opacity: 0; overflow: visible; } @keyframes fade-in { to { opacity: 1; } } .bulb, .broken-glow, .glow { mix-blend-mode: lighten; opacity: 0.9; transform-box: fill-box; transform-origin: center bottom; } .broken-bulb { mix-blend-mode: lighten; opacity: 0.9; transform-box: fill-box; transform-origin: center bottom; } .glow, .broken-glow { opacity: 0; mix-blend-mode: soft-light; } </style> </head> <body translate="no" > <svg id="svg" viewBox="0 0 200 205" preserveAspectRatio="xMaxYMin meet"> <rect id="floor" width="204.25" height="700" x="-2.61" y="59.47" fill="#969393" opacity="0.5" /> <rect id="wall" width="2000" height="61.95" x="-1800" y="-1" fill="hsl(0deg 0% 90%)" /> <g id="socket"> <polygon fill="grey" points="150 39.83 180 60.99 200 60.99 200 28 180 10.7 180 39.83" opacity=".14" style="mix-blend-mode:multiply" /> <path fill="white" d="M180,12.36v26.83a1.56,1.56,0,0,1,-1.55,1.56h-26.53a1.56,1.56,0,0,1,-1.55,-1.56v-26.83a1.56,1.56,0,0,1,1.55,-1.56h26.53a1.56,1.56,0,0,1,1.55,1.56z" /> <rect width="2.11" height="5.78" x="163.5" y="18.42" fill="#4a494a" rx="1.05" /> <rect height="2.11" width="4.45" x="168" y="31" fill="#4a494a" rx="1.05" /> <rect height="2.11" width="4.45" x="157" y="31" fill="#4a494a" rx="1.05" /> </g> <g id="cableCont"> <path class="cable" stroke-linecap="round" fill="none" stroke-width="1.2" stroke="#3a3337" id="path" /> </g> <g id="gubbins"> </g> <g id="plug"> <path fill="#3a3337" d="M185,83.91l-4.4,-5.8a3.23,3.23,0,0,0,-2.58,-1.28h-0.79a3.11,3.11,0,0,0,-0.43,0h-3.7a2,2,0,0,0,-0.66,0.11a3.26,3.26,0,0,0,-2.25,1.27l-4.41,5.79a3.22,3.22,0,0,0,-0.66,2v7a3.25,3.25,0,0,0,2.64,3.19l5.13,1a3.25,3.25,0,0,0,2.59,-0.62a3.26,3.26,0,0,0,2.42,0.49l5.13,-1a3.24,3.24,0,0,0,2.63,-3.19v-7a3.24,3.24,0,0,0,-0.66,-1.96z" /> <rect width="4.27" height="7.42" x="173.5" y="92" fill="#3a3330" rx="2.13" /> </g> </svg> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.5.2.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/Draggable3.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/EasePack.3.51.js"></script> <script> const svg = document.querySelector("svg"); const gubbins = document.querySelector("#gubbins"); const cableCont = document.querySelector("#cableCont"); const svgns = "http://www.w3.org/2000/svg"; const defs = document.createElementNS(svgns, "defs"); const cable = document.querySelector(".cable"); svg.appendChild(defs); const button = document.querySelector(".button"); let tension = 1.3; let numOfPoints = 22; let randomBulb = gsap.utils.random(4, numOfPoints - 6, 2); // hard coding some values for the start of the lights curve let points = [175, 95, 175, 120, 175, 150]; let x = points[4]; let y = points[5]; let goingRight; let goingUp; let hasDoneRender; let tl = gsap.timeline({ paused: true }); function addTimeline() { let brokenBulb = document.querySelector(".bulb:nth-of-type(4)"); let brokenGlow = document.querySelector(".glow:nth-of-type(4)"); tl .to(".bulb", { stagger: 0.07, "mix-blend-mode": "screen" }) .to( ".glow", { stagger: 0.07, opacity: 0.8 }, "<" ) .to(".broken-bulb", { duration: 2, opacity: 0.1, "mix-blend-mode": "screen", yoyo: true, ease: RoughEase.ease.config({ points: 50, strength: 2, clamp: true }) }) .to( ".broken-glow", { duration: 2, opacity: 1, yoyo: true, ease: RoughEase.ease.config({ points: 50, strength: 2, clamp: true }) }, "<" ) .to(".broken-glow", { opacity: 0 }) .to( ".broken-bulb", { opacity: 0.8, fill: "grey", "mix-blend-mode": "unset" }, "<" ); } function calcAngle(opp, adj) { return Math.atan(opp / adj); } function addGradient(loopCount) { var stops = [ { color: `hsl(${loopCount * 10} 100% 100%)`, offset: "0%" }, { color: `hsl(${loopCount * 10} 100% 80%)`, offset: "20%" }, { color: `hsla(${loopCount * 10}, 100%, 80%, 0)`, offset: "100%" } ]; var gradient = document.createElementNS(svgns, "radialGradient"); for (var i = 0.........完整代码请登录后点击上方下载按钮下载查看
网友评论0