|
| 1 | +<script> |
| 2 | + import { gsap } from 'gsap'; |
| 3 | +</script> |
| 4 | + |
| 5 | +<svg |
| 6 | + class="toggle-scene" |
| 7 | + xmlns="http://www.w3.org/2000/svg" |
| 8 | + preserveaspectratio="xMinYMin" |
| 9 | + viewBox="0 0 197.451 481.081" |
| 10 | +> |
| 11 | + <defs> |
| 12 | + <marker id="e" orient="auto" overflow="visible" refx="0" refy="0"> |
| 13 | + <path |
| 14 | + class="toggle-scene__cord-end" |
| 15 | + fill-rule="evenodd" |
| 16 | + stroke-width=".2666" |
| 17 | + d="M.98 0a1 1 0 11-2 0 1 1 0 012 0z" |
| 18 | + /> |
| 19 | + </marker> |
| 20 | + <marker id="d" orient="auto" overflow="visible" refx="0" refy="0"> |
| 21 | + <path |
| 22 | + class="toggle-scene__cord-end" |
| 23 | + fill-rule="evenodd" |
| 24 | + stroke-width=".2666" |
| 25 | + d="M.98 0a1 1 0 11-2 0 1 1 0 012 0z" |
| 26 | + /> |
| 27 | + </marker> |
| 28 | + <marker id="c" orient="auto" overflow="visible" refx="0" refy="0"> |
| 29 | + <path |
| 30 | + class="toggle-scene__cord-end" |
| 31 | + fill-rule="evenodd" |
| 32 | + stroke-width=".2666" |
| 33 | + d="M.98 0a1 1 0 11-2 0 1 1 0 012 0z" |
| 34 | + /> |
| 35 | + </marker> |
| 36 | + <marker id="b" orient="auto" overflow="visible" refx="0" refy="0"> |
| 37 | + <path |
| 38 | + class="toggle-scene__cord-end" |
| 39 | + fill-rule="evenodd" |
| 40 | + stroke-width=".2666" |
| 41 | + d="M.98 0a1 1 0 11-2 0 1 1 0 012 0z" |
| 42 | + /> |
| 43 | + </marker> |
| 44 | + <marker id="a" orient="auto" overflow="visible" refx="0" refy="0"> |
| 45 | + <path |
| 46 | + class="toggle-scene__cord-end" |
| 47 | + fill-rule="evenodd" |
| 48 | + stroke-width=".2666" |
| 49 | + d="M.98 0a1 1 0 11-2 0 1 1 0 012 0z" |
| 50 | + /> |
| 51 | + </marker> |
| 52 | + <clippath id="g" clippathunits="userSpaceOnUse"> |
| 53 | + <path |
| 54 | + stroke-linecap="round" |
| 55 | + stroke-linejoin="round" |
| 56 | + stroke-width="4.677" |
| 57 | + d="M-774.546 827.629s12.917-13.473 29.203-13.412c16.53.062 29.203 13.412 29.203 13.412v53.6s-8.825 16-29.203 16c-21.674 0-29.203-16-29.203-16z" |
| 58 | + /> |
| 59 | + </clippath> |
| 60 | + <clippath id="f" clippathunits="userSpaceOnUse"> |
| 61 | + <path |
| 62 | + d="M-868.418 945.051c-4.188 73.011 78.255 53.244 150.216 52.941 82.387-.346 98.921-19.444 98.921-47.058 0-27.615-4.788-42.55-73.823-42.55-69.036 0-171.436-30.937-175.314 36.667z" |
| 63 | + /> |
| 64 | + </clippath> |
| 65 | + </defs> |
| 66 | + <g class="toggle-scene__cords"> |
| 67 | + <path |
| 68 | + class="toggle-scene__cord" |
| 69 | + marker-end="url(#a)" |
| 70 | + fill="none" |
| 71 | + stroke-linecap="square" |
| 72 | + stroke-width="6" |
| 73 | + d="M123.228-28.56v150.493" |
| 74 | + transform="translate(-24.503 256.106)" |
| 75 | + /> |
| 76 | + <path |
| 77 | + class="toggle-scene__cord" |
| 78 | + marker-end="url(#a)" |
| 79 | + fill="none" |
| 80 | + stroke-linecap="square" |
| 81 | + stroke-width="6" |
| 82 | + d="M123.228-28.59s28 8.131 28 19.506-18.667 13.005-28 19.507c-9.333 6.502-28 8.131-28 19.506s28 19.507 28 19.507" |
| 83 | + transform="translate(-24.503 256.106)" |
| 84 | + /> |
| 85 | + <path |
| 86 | + class="toggle-scene__cord" |
| 87 | + marker-end="url(#a)" |
| 88 | + fill="none" |
| 89 | + stroke-linecap="square" |
| 90 | + stroke-width="6" |
| 91 | + d="M123.228-28.575s-20 16.871-20 28.468c0 11.597 13.333 18.978 20 28.468 6.667 9.489 20 16.87 20 28.467 0 11.597-20 28.468-20 28.468" |
| 92 | + transform="translate(-24.503 256.106)" |
| 93 | + /> |
| 94 | + <path |
| 95 | + class="toggle-scene__cord" |
| 96 | + marker-end="url(#a)" |
| 97 | + fill="none" |
| 98 | + stroke-linecap="square" |
| 99 | + stroke-width="6" |
| 100 | + d="M123.228-28.569s16 20.623 16 32.782c0 12.16-10.667 21.855-16 32.782-5.333 10.928-16 20.623-16 32.782 0 12.16 16 32.782 16 32.782" |
| 101 | + transform="translate(-24.503 256.106)" |
| 102 | + /> |
| 103 | + <path |
| 104 | + class="toggle-scene__cord" |
| 105 | + marker-end="url(#a)" |
| 106 | + fill="none" |
| 107 | + stroke-linecap="square" |
| 108 | + stroke-width="6" |
| 109 | + d="M123.228-28.563s-10 24.647-10 37.623c0 12.977 6.667 25.082 10 37.623 3.333 12.541 10 24.647 10 37.623 0 12.977-10 37.623-10 37.623" |
| 110 | + transform="translate(-24.503 256.106)" |
| 111 | + /> |
| 112 | + <g class="line toggle-scene__dummy-cord"> |
| 113 | + <line marker-end="url(#a)" x1="98.7255" x2="98.7255" y1="240.5405" y2="380.5405" /> |
| 114 | + </g> |
| 115 | + <circle class="toggle-scene__hit-spot" cx="98.7255" cy="380.5405" r="60" fill="transparent" /> |
| 116 | + </g> |
| 117 | + <g class="toggle-scene__bulb bulb" transform="translate(844.069 -645.213)"> |
| 118 | + <path |
| 119 | + class="bulb__cap" |
| 120 | + stroke-linecap="round" |
| 121 | + stroke-linejoin="round" |
| 122 | + stroke-width="4.677" |
| 123 | + d="M-774.546 827.629s12.917-13.473 29.203-13.412c16.53.062 29.203 13.412 29.203 13.412v53.6s-8.825 16-29.203 16c-21.674 0-29.203-16-29.203-16z" |
| 124 | + /> |
| 125 | + <path |
| 126 | + class="bulb__cap-shine" |
| 127 | + d="M-778.379 802.873h25.512v118.409h-25.512z" |
| 128 | + clip-path="url(#g)" |
| 129 | + transform="matrix(.52452 0 0 .90177 -368.282 82.976)" |
| 130 | + /> |
| 131 | + <path |
| 132 | + class="bulb__cap" |
| 133 | + stroke-linecap="round" |
| 134 | + stroke-linejoin="round" |
| 135 | + stroke-width="4" |
| 136 | + d="M-774.546 827.629s12.917-13.473 29.203-13.412c16.53.062 29.203 13.412 29.203 13.412v0s-8.439 10.115-28.817 10.115c-21.673 0-29.59-10.115-29.59-10.115z" |
| 137 | + /> |
| 138 | + <path |
| 139 | + class="bulb__cap-outline" |
| 140 | + fill="none" |
| 141 | + stroke-linecap="round" |
| 142 | + stroke-linejoin="round" |
| 143 | + stroke-width="4.677" |
| 144 | + d="M-774.546 827.629s12.917-13.473 29.203-13.412c16.53.062 29.203 13.412 29.203 13.412v53.6s-8.825 16-29.203 16c-21.674 0-29.203-16-29.203-16z" |
| 145 | + /> |
| 146 | + <g class="bulb__filament" fill="none" stroke-linecap="round" stroke-width="5"> |
| 147 | + <path d="M-752.914 823.875l-8.858-33.06" /> |
| 148 | + <path d="M-737.772 823.875l8.858-33.06" /> |
| 149 | + </g> |
| 150 | + <path |
| 151 | + class="bulb__bulb" |
| 152 | + stroke-linecap="round" |
| 153 | + stroke-width="5" |
| 154 | + d="M-783.192 803.855c5.251 8.815 5.295 21.32 13.272 27.774 12.299 8.045 36.46 8.115 49.127 0 7.976-6.454 8.022-18.96 13.273-27.774 3.992-6.7 14.408-19.811 14.408-19.811 8.276-11.539 12.769-24.594 12.769-38.699 0-35.898-29.102-65-65-65-35.899 0-65 29.102-65 65 0 13.667 4.217 26.348 12.405 38.2 0 0 10.754 13.61 14.746 20.31z" |
| 155 | + /> |
| 156 | + <circle |
| 157 | + class="bulb__flash" |
| 158 | + cx="-745.343" |
| 159 | + cy="743.939" |
| 160 | + r="83.725" |
| 161 | + fill="none" |
| 162 | + stroke-dasharray="10,30" |
| 163 | + stroke-linecap="round" |
| 164 | + stroke-linejoin="round" |
| 165 | + stroke-width="10" |
| 166 | + /> |
| 167 | + <path |
| 168 | + class="bulb__shine" |
| 169 | + fill="none" |
| 170 | + stroke-linecap="round" |
| 171 | + stroke-linejoin="round" |
| 172 | + stroke-width="12" |
| 173 | + d="M-789.19 757.501a45.897 45.897 0 013.915-36.189 45.897 45.897 0 0129.031-21.957" |
| 174 | + /> |
| 175 | + </g> |
| 176 | +</svg> |
| 177 | + |
| 178 | +<style> |
| 179 | +
|
| 180 | +:root{ |
| 181 | + --on 0 |
| 182 | + --bg 'hsl(%s, %s, %s)' % (calc(200 - (var(--on) * 160)) calc((20 + (var(--on) * 50)) * 1%) calc((20 + (var(--on) * 60)) * 1%)) |
| 183 | + --cord 'hsl(0, 0%, %s)' % (calc((60 - (var(--on) * 50)) * 1%)) |
| 184 | + --stroke 'hsl(0, 0%, %s)' % (calc((60 - (var(--on) * 50)) * 1%)) |
| 185 | + --shine 'hsla(0, 0%, 100%, %s)' % calc(0.75 - (var(--on) * 0.5)) |
| 186 | + --cap 'hsl(0, 0%, %s)' % calc((40 + (var(--on) * 30)) * 1%) |
| 187 | + --filament 'hsl(45, %s, %s)' % (calc(var(--on) * 80%) calc((25 + (var(--on) * 75)) * 1%)) |
| 188 | +} |
| 189 | +body{ |
| 190 | + min-height 100vh |
| 191 | + display flex |
| 192 | + align-items center |
| 193 | + justify-content center |
| 194 | + background var(--bg) |
| 195 | +} |
| 196 | +
|
| 197 | +.toggle-scene{ |
| 198 | + // !important for CodePen |
| 199 | + overflow visible !important |
| 200 | + height 50vmin |
| 201 | + position absolute |
| 202 | +
|
| 203 | + &__cord |
| 204 | + stroke var(--cord) |
| 205 | + cursor move |
| 206 | +
|
| 207 | + // Hide all cords if there's no JavaScript? |
| 208 | + &:nth-of-type(1) |
| 209 | + display none |
| 210 | +
|
| 211 | + // Hide cords by default |
| 212 | + &:nth-of-type(2) |
| 213 | + &:nth-of-type(3) |
| 214 | + &:nth-of-type(4) |
| 215 | + &:nth-of-type(5) |
| 216 | + display none |
| 217 | +
|
| 218 | + &-end |
| 219 | + stroke var(--cord) |
| 220 | + fill var(--cord) |
| 221 | +} |
| 222 | +.toggle-scene__dummy-cord{ |
| 223 | + stroke-width 6 |
| 224 | + stroke var(--cord) |
| 225 | +} |
| 226 | +
|
| 227 | +.bulb{ |
| 228 | + &__filament |
| 229 | + stroke var(--filament) |
| 230 | + &__shine |
| 231 | + stroke var(--shine) |
| 232 | + &__flash |
| 233 | + stroke hsl(45, 80%, 80%) |
| 234 | + display none |
| 235 | + &__bulb |
| 236 | + stroke var(--stroke) |
| 237 | + fill 'hsla(%s, 80%, 80%, %s)' % (calc(180 - (95 * var(--on))) calc(0.1 + (0.4 * var(--on)))) |
| 238 | + &__cap |
| 239 | + fill var(--cap) |
| 240 | + &-shine |
| 241 | + fill var(--shine) |
| 242 | + &-outline |
| 243 | + stroke var(--stroke) |
| 244 | +} |
| 245 | +</style> |
0 commit comments