gsap实现牛顿摆灯泡摆动点亮动画效果代码
代码语言:html
所属分类:动画
代码描述:gsap实现牛顿摆灯泡摆动点亮动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> * { box-sizing: border-box; } :root { --filament-saturation: 0; --filament-lightness: 40; --fitting-lightness: 30; --chord-lightness: 50; --bg-lightness: 5; --glass-lightness: 30; --glass-saturation: 0; --light-alpha: 0; --ceiling: 50; --bulb-hue: 60; } body { background: hsl(215, 100%, calc(var(--bg-lightness) * 1%)); display: flex; align-items: center; justify-content: center; min-height: 100vh; } svg { width: 90vmin; transform: translate(0, -30%); } .wrapper { position: relative; } .wrapper:after { content: ""; width: 90vmin; position: absolute; bottom: 130%; left: 0%; border-bottom: 4px solid hsl(0, 0%, calc(var(--ceiling) * 1%)); transform: translate(0, 2px); } .light-bulb { display: block; } .light-bulb__chord { stroke: hsl(0, 0%, calc(var(--chord-lightness) * 1%)); } .light-bulb__glass { fill: hsla(var(--bulb-hue), 100%, calc(var(--glass-lightness) * 1%), var(--light-alpha)); stroke: hsla(var(--bulb-hue), calc(var(--glass-saturation) * 1%), calc(var(--glass-lightness) * 1%), 1); } .light-bulb__filament { fill: none; stroke: hsl(60, calc(var(--filament-saturation) * 1%), calc(var(--filament-lightness) * 1%)); } .light-bulb__fitting { fill: hsl(0, 0%, calc(var(--fitting-lightness) * 1%)); } .light-bulb__fitting-shine { fill: hsl(0, 0%, calc((var(--fitting-lightness) + 20) * 1%)); } .light-bulb__bloom { fill: none; stroke: hsl(var(--bulb-hue), 100%, 50%); stroke-width: 2; opacity: 0; } [type='checkbox'] { position: fixed; bottom: 1rem; opacity: 0.1; } [type='checkbox']:nth-of-type(1) { right: 1rem; } [type='checkbox']:nth-of-type(1):checked ~ .wrapper svg .light-bulb:nth-of-type(odd) { --bulb-hue: 90; } [type='checkbox']:nth-of-type(1):checked ~ .wrapper svg .light-bulb:nth-of-type(even) { --bulb-hue: 0; } [type='checkbox']:nth-of-type(2) { right: 2rem; } [type='checkbox']:nth-of-type(2):checked ~ .wrapper svg .light-bulb--1 { --bulb-hue: 0; } [type='checkbox']:nth-of-type(2):checked ~ .wrapper svg .light-bulb--2 { --bulb-hue: 30; } [type='checkbox']:nth-of-type(2):checked ~ .wrapper svg .light-bulb--3 { --bulb-hue: 60; } [type='checkbox']:nth-of-type(2):checked ~ .wrapper svg .light-bulb--4 { --bulb-hue: 90; } [type='checkbox']:nth-of-type(2):checked ~ .wrapper svg .light-bulb--5 { --bulb-hue: 200; } [type='checkbox']:nth-of-type(2):checked ~ .wrapper svg .light-bulb--6 { --bulb-hue: 270; } [type='checkbox']:nth-of-type(3) { right: 3rem; } [type='checkbox']:nth-of-type(3):checked ~ .wrapper svg .light-bulb--1 { --bulb-hue: 60; } [type='checkbox']:nth-of-type(3):checked ~ .wrapper svg .light-bulb--2 { --bulb-hue: 120; } [type='checkbox']:nth-of-type(3):checked ~ .wrapper svg .light-bulb--3 { --bulb-hue: 180; } [type='checkbox']:nth-of-type(3):checked ~ .wrapper svg .light-bulb--4 { --bulb-hue: 240; } [type='checkbox']:nth-of-type(3):checked ~ .wrapper svg .light-bulb--5 { --bulb-hue: 300; } [type='checkbox']:nth-of-type(3):checked ~ .wrapper svg .light-bulb--6 { --bulb-hue: 360; } [type='checkbox']:nth-of-type(4) { right: 4rem; } [type='checkbox']:nth-of-type(4):checked ~ .wrapper svg .light-bulb--1 { --bulb-hue: 10; } [type='checkbox']:nth-of-type(4):checked ~ .wrapper svg .light-bulb--2 { --bulb-hue: 20; } [type='checkbox']:nth-of-type(4):checked ~ .wrapper svg .light-bulb--3 { --bulb-hue: 30; } [type='checkbox']:nth-of-type(4):checked ~ .wrapper svg .light-bulb--4 { --bulb-hue: 40; } [type='checkbox']:nth-of-type(4):checked ~ .wrapper svg .light-bulb--5 { --bulb-hue: 50; } [type='checkbox']:nth-of-type(4):checked ~ .wrapper svg .light-bulb--6 { --bulb-hue: 60; } .banner-container { position: fixed; bottom: 0; left: 50%; transform: translate(-50%, 0); } .hue-banner { color: hsl(var(--hue, 0), 100%, 50%); border-color: hsl(var(--hue, 0), 100%, 50%); border-style: solid; border-width: 4px; border-radius: 4px; margin-bottom: 1rem; padding: 1rem; font-weight: bold; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; line-height: 1.5; -webkit-animation: fadeToBlack 0.5s 1s both; animation: fadeToBlack 0.5s 1s both; } @-webkit-keyframes fadeToBlack { to { opacity: 0; } } @keyframes fadeToBlack { to { opacity: 0; } } </style> </head> <body > <input type="checkbox"/> <input type="checkbox"/> <input type="checkbox"/> <input type="checkbox"/> <div class="wrapper"> <svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 98.138617 90.336713"> <g class="light-bulb light-bulb--3"> <path class="light-bulb__chord" d="M45.1005633.00870392v68.74491" fill="none" stroke-width=".5291667"></path> <g class="light-bulb__bulb" transform="translate(2.5955317 -211.35093658)"> <circle class="light-bulb__glass" r="3.8407259" cy="286.7189" cx="42.372742" stroke-width=".25604835" stroke-linecap="round" stroke-linejoin="round"></circle> <rect class="light-bulb__fitting" ry=".37417734" y="279.35907" x="39.8592" height="3.96875" width="5.2916665"></rect> <g class="light-bulb__filament"> <path class="light-bulb__filament" d="M43.563367 283.32784v2.64583M41.446699 283.32784v2.64583" stroke-width=".21696301"></path> <path class="light-bulb__filament" d="M42.505033 285.17992v1.32292M41.975866 285.17992v1.32292M43.0342 285.17992v1.32292" stroke-width=".25654384"></path> </g> <path class="light-bulb__fitting-shine" d="M43.298786 279.35907h1.5875v3.96875h-1.5875z"></path> <circle class="light-bulb__bloom" r="3.5018382" cx="42.372742" cy="286.7189" stroke-width=".93382347" stroke-linecap="round" stroke-linejoin="round"></circle> </g> </g> <g class="light-bulb light-bulb--6"> <path class="light-bulb__chord" d="M68.9130633.00870392v68.74491" fill="none" stroke-width=".5291667"></path> <g class="light-bulb__bulb" transform="translate(26.4080317 -211.35093658)"> <circle class="light-bulb__glass" cx="42.372742" cy="286.7189" r="3.8407259" stroke-width=".25604835" stroke-linecap="round" stroke-linejoin="round"></circle> <rect class="light-bulb__fitting" width="5.2916665" height="3.96875" x="39.8592" y="279.35907" ry=".37417734"></rect> <g class="light-bulb__filament"> <path class="light-bulb__filament" d="M43.563367 283.32784v2.64583M41.446699 283.32784v2.64583" stroke-width=".21696301"></path> <path class="light-bulb__filament" d="M42.505033 285.17992v1.32292M41.975866 285.17992v1.32292M43.0342 285.17992v1.32292" stroke-width=".25654384"></path> </g> <path class="light-bulb__fitting-shine" d="M43.298786 279.35907h1.5875v3.96875h-1.5875z"></path> <circle class="light-bulb__bloom" cy="286.7189" cx="42.372742" r="3.5018382" stroke-linecap="round" stroke-linejoin="round"></circle> </g> </g> <g class="light-bulb light-bulb--5"> <path class="light-bulb__chord" d="M60.9755633.00870392v68.74491" fill="none" stroke-width=".5291667"></path> <g class="light-bulb__bulb" transform="translate(18.4705317 -211.35093658)"> <circle class="light-bulb__glass" r="3.8407259" cy="286.7189" cx="42.372742" stroke-width=".25604835" stroke-linecap="round" stroke-linejoin="round"></circle> <rect class="light-bulb__fitting" ry=".37417734" y="279.35907" x="39.8592" height="3.96875" width="5.2916665"></rect> <g class="light-bulb__filament"> <path class="light-bulb__filament" d="M43.563367 283.32784v2.64583M41.446699 283.32784v2.64583" stroke-width=".21696301"></path> <path class="light-bulb__filament" d="M42.505033 285.17992v1.32292M41.975866 285.17992v1.32292M43.0342 285.17992v1.32292" stroke-width=".25654384"></path> </g> <path class="light-bulb__fitting-shine" d="M43.298786 279.35907h1.5875v3.96875h-1.5875z"></path> <circle class="light-bulb__bloom" r="3.5018382" cx="42.372742" cy="286.7189" stroke-linecap="round" stroke-linejoin="round"></circle> </g> </g> <g class="light-bulb light-bulb--2"> <path class="light-bulb__chord" d="M37.1630633.00870392v68.74491" fill="none" stroke-width=".5291667"></path> <g class="light-bulb__bulb" transform="translate(-5.3419683 -211.35093658)"> <circle class="light-bulb__glass" cx="42.372742" cy="286.7189" r="3.8407259" stroke-width=".25604835" stroke-linecap="round" stroke-linejoin="round"></circle> <rect class="light-bulb__fitting" width="5.2916665" height="3.96875" x="39.8592" y="279.35907" ry=".37417734"></rect> <g class="light-bulb__filament"> <path class="light-bulb__filament" d="M43.563367 283.32784v2.64583M41.446699 283.32784v2.64583" stroke-width=".21696301"></path> <path class="light-bulb__filament" d="M42.505033 285.17992v1.32292M41.975866 285.17992v1.32292M43.0342 285.17992v1.32292" stroke-width=".25654384"></path> </g> <path class="light-bulb__fitting-shine" d="M43.298786 279.35907h1.5875v3.96875h-1.5875z"></path> <circle class="light-bulb__bloom" cy="286.7189" cx="42.372742" r="3.5018382" stroke-linecap="round" stroke-linejoin="round"></circle> </g> </g> <g class="light-bulb light-bulb--1"> <path class="light-bulb__chord" d="M29.2255633.00870392v68.74491" fill="none" stroke-width=".5291667"></path> <g class="light-bulb__bulb" transform="translate(-13.2794683 -211.35093658)"> <circle class="light-bulb__glass" r="3.8407259" cy="286.7189" cx="42.372742" stroke-width=".25604835" stroke-linecap="round" stroke-linejoin="round"></circle> <rect class="light-bulb__fitting" ry=".37417734" y="279.35907" x="39.8592" height="3.96875" width="5.2916665"></rect> <g class="light-bulb__filament"> <path class="light-bulb__filamen.........完整代码请登录后点击上方下载按钮下载查看
网友评论0