Rainbow Loop
Home
Snippets
Rainbow Loop
HTML
CSS
JS
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500" fill="none" stroke-width="15" stroke-linecap="round"> <use href="#lines" stroke-width="35" opacity="0.3" stroke-linecap="square"/> <g id="lines"> <path d="M42.5 445V287.58c0-122.6 98.36-221.4 220.69-213.36 108.81 7.16 194.86 97.7 194 208V445"/> <path d="M86 445V275.78c0-77.51 78.73-164 174.7-158.9 85.36 4.53 152.86 85.77 152.86 156V445"/> <path d="M130 445V283.9c0-70.47 57.69-127.26 128-122.64 62.54 4.12 112 56.15 112 120v164"/> <path d="M173.5 445V282.35c0-44.93 36.77-81.13 81.6-78.18A76.5 76.5 0 0 1 326 280V445"/> <path d="M217 445V281.8c0-19.38 15.86-35 35.2-33.73C268.4 249.2 283 263.51 283 281v164"/> </g> </svg> <script src="https://unpkg.com/gsap@3/dist/gsap.min.js"></script> <script src="https://unpkg.com/gsap@3/dist/DrawSVGPlugin.min.js"></script> <script src="https://unpkg.com/gsap@3/dist/CustomEase.min.js"></script>
body { height:100vh; display:flex; align-items:center; justify-content:center; background:#211e1a; } svg { width:80%; max-height:80%; filter:saturate(1); }
const paths = document.querySelectorAll("svg path"); const hex = ["323a8f", "008059", "fd9e26", "c40001", "f01f47"]; const ez = (i) => CustomEase.create("ez", "M0,0 C0.6,0.16 " + (0.6-(i+1)/8) + ",1 1,1"); const tl = gsap.timeline({ repeat: -1 }); paths.forEach((p, i) => { const length = p.getTotalLength(); tl.add( gsap.timeline() .set(p, { stroke: "#" + hex[i] }) .from(p, { duration: 1.9, drawSVG: "0 35", ease: ez(5-i) }) .to(p, { duration: 1.1, drawSVG: length - 35 + " 100%", ease: ez(i) }, "-=0.1") .to(p, { duration: 0.9, stroke: "#" + hex[4 - i], x: -240, ease: ez(i) }, "-=0.2") , 0); }); gsap.from(tl, { duration:2, timeScale: 0, ease: "sine.in" }); window.onpointerup = () => { const state = tl.isActive() ? 0 : 1 gsap.to(tl, { timeScale: state }); if ( !state ) gsap.to(tl, { progress: Math.round( tl.progress() ), ease: "sine" }); gsap.to('svg', { filter: "saturate(" + state + ")" }); gsap.to('body', { background: ["#111", "#211e1a"][state] }); } const ua = navigator.userAgent; if ( ua.indexOf("Safari") > -1 && ua.indexOf("Chrome") === -1) { gsap.set('use', { display: "none" }); gsap.set('svg', { "stroke-width": 25 }); }
Ad #1
Ad #2
Scroll to Top