|
1 | 1 | <div
|
2 | 2 | x-on:click="darkMode = !darkMode"
|
3 | 3 | x-data="{
|
4 |
| - nightToDay: [ |
5 |
| - [ |
6 |
| - '.theme-selector-moon', |
7 |
| - { |
8 |
| - opacity: [1, 0], |
9 |
| - transform: |
10 |
| - 'translate(0%, -50%) translate(12px, 0px) rotate(70deg) scale(0.6, 0.6)', |
11 |
| - }, |
12 |
| - { duration: 0.3, ease: motion.easeOut }, |
13 |
| - ], |
| 4 | + timeline: null, |
14 | 5 |
|
15 |
| - [ |
16 |
| - '.theme-selector-mini-star', |
17 |
| - { opacity: [1, 0], scale: [1, 0] }, |
18 |
| - { duration: 0.3, ease: motion.easeOut, at: 0 }, |
19 |
| - ], |
20 |
| -
|
21 |
| - [ |
22 |
| - '.theme-selector-micro-star', |
23 |
| - { opacity: [1, 0], scale: [1, 0] }, |
24 |
| - { duration: 0.3, ease: motion.easeOut, at: 0 }, |
25 |
| - ], |
26 |
| -
|
27 |
| - [ |
28 |
| - '.theme-selector-sunball', |
29 |
| - { opacity: [0, 1], x: [-5, 0], y: [-5, 0], scale: [0, 1] }, |
30 |
| - { |
31 |
| - duration: 0.3, |
32 |
| - ease: motion.easeOut, |
33 |
| - at: 0.15, |
34 |
| - }, |
35 |
| - ], |
36 |
| -
|
37 |
| - [ |
38 |
| - '.theme-selector-sunshine', |
39 |
| - { opacity: [0, 1], scale: [0, 1], rotate: [-180, 0] }, |
40 |
| - { |
41 |
| - duration: 0.3, |
42 |
| - ease: motion.easeOut, |
43 |
| - at: 0.15, |
44 |
| - }, |
45 |
| - ], |
46 |
| - ], |
47 |
| - dayToNight: [ |
48 |
| - [ |
49 |
| - '.theme-selector-sunshine', |
50 |
| - { opacity: [1, 0], scale: [1, 0], rotate: [0, -180] }, |
51 |
| - { |
52 |
| - duration: 0.3, |
53 |
| - ease: motion.easeOut, |
54 |
| - }, |
55 |
| - ], |
| 6 | + init() { |
| 7 | + gsap.to('.theme-selector', { |
| 8 | + scale: 1, |
| 9 | + duration: 0.1, |
| 10 | + }) |
56 | 11 |
|
57 |
| - [ |
58 |
| - '.theme-selector-sunball', |
59 |
| - { opacity: [1, 0], x: [0, -5], y: [0, -5], scale: [1, 0] }, |
60 |
| - { |
| 12 | + timeline = gsap |
| 13 | + .timeline({ |
| 14 | + paused: true, |
| 15 | + }) |
| 16 | + .to('.theme-selector-moon', { |
| 17 | + rotate: 70, |
| 18 | + ease: 'sine.out', |
61 | 19 | duration: 0.3,
|
62 |
| - ease: motion.easeOut, |
63 |
| - at: 0.15, |
64 |
| - }, |
65 |
| - ], |
66 |
| -
|
67 |
| - [ |
68 |
| - '.theme-selector-micro-star', |
69 |
| - { opacity: [0, 1], scale: [0, 1] }, |
70 |
| - { duration: 0.3, ease: motion.easeOut, at: 0 }, |
71 |
| - ], |
72 |
| -
|
73 |
| - [ |
74 |
| - '.theme-selector-mini-star', |
75 |
| - { opacity: [0, 1], scale: [0, 1] }, |
76 |
| - { duration: 0.3, ease: motion.easeOut, at: 0 }, |
77 |
| - ], |
78 |
| -
|
79 |
| - [ |
80 |
| - '.theme-selector-moon', |
81 |
| - { |
82 |
| - opacity: [0, 1], |
83 |
| - transform: 'translate(0%, -50%) translate(12px, 0px)', |
84 |
| - }, |
85 |
| - { duration: 0.3, ease: motion.easeOut, at: 0 }, |
86 |
| - ], |
87 |
| - ], |
88 |
| - setInitialState() { |
89 |
| - // Set initial state directly without animation |
90 |
| - if (! darkMode) { |
91 |
| - document.querySelector('.theme-selector-sunball').style.opacity = |
92 |
| - '0' |
93 |
| - document.querySelector('.theme-selector-sunshine').style.opacity = |
94 |
| - '0' |
95 |
| - document.querySelector('.theme-selector-moon').style.transform = |
96 |
| - 'translate(0%, -50%) translate(12px, 0px)' |
97 |
| - } else { |
98 |
| - document.querySelector('.theme-selector-moon').style.opacity = '0' |
99 |
| - document.querySelector('.theme-selector-moon').style.transform = |
100 |
| - 'translate(0%, -50%) translate(12px, 0px) rotate(70deg) scale(0.6, 0.6)' |
101 |
| - document.querySelector('.theme-selector-mini-star').style.opacity = |
102 |
| - '0' |
103 |
| - document.querySelector('.theme-selector-micro-star').style.opacity = |
104 |
| - '0' |
105 |
| - } |
106 |
| - }, |
107 |
| - init() { |
108 |
| - motion.animate($el, { scale: 1 }, { duration: 0.1 }) |
| 20 | + }) |
| 21 | + .to( |
| 22 | + '.theme-selector-mini-star', |
| 23 | + { |
| 24 | + autoAlpha: 0, |
| 25 | + scale: 0, |
| 26 | + ease: 'sine.out', |
| 27 | + duration: 0.3, |
| 28 | + }, |
| 29 | + '>-0.3', |
| 30 | + ) |
| 31 | + .to( |
| 32 | + '.theme-selector-micro-star', |
| 33 | + { |
| 34 | + autoAlpha: 0, |
| 35 | + scale: 0, |
| 36 | + ease: 'sine.out', |
| 37 | + duration: 0.3, |
| 38 | + }, |
| 39 | + '<', |
| 40 | + ) |
| 41 | + .to( |
| 42 | + '.theme-selector-moon', |
| 43 | + { |
| 44 | + scale: 0.6, |
| 45 | + ease: 'sine.out', |
| 46 | + duration: 0.3, |
| 47 | + }, |
| 48 | + '<', |
| 49 | + ) |
| 50 | + .fromTo( |
| 51 | + '.theme-selector-sunball', |
| 52 | + { |
| 53 | + scale: 0, |
| 54 | + x: -5, |
| 55 | + y: 5, |
| 56 | + }, |
| 57 | + { |
| 58 | + x: 0, |
| 59 | + y: 0, |
| 60 | + scale: 1, |
| 61 | + ease: 'expo.out', |
| 62 | + duration: 0.3, |
| 63 | + }, |
| 64 | + '>-0.15', |
| 65 | + ) |
| 66 | + .fromTo( |
| 67 | + '.theme-selector-sunshine', |
| 68 | + { |
| 69 | + scale: 0, |
| 70 | + rotate: -180, |
| 71 | + }, |
| 72 | + { |
| 73 | + scale: 1, |
| 74 | + rotate: 0, |
| 75 | + ease: 'expo.out', |
| 76 | + duration: 0.3, |
| 77 | + }, |
| 78 | + '<', |
| 79 | + ) |
109 | 80 |
|
110 |
| - this.setInitialState() |
| 81 | + if (darkMode) timeline.progress(1) |
111 | 82 |
|
112 |
| - // Watch for dark mode changes |
113 | 83 | $watch('darkMode', (value) => {
|
114 | 84 | if (value) {
|
115 |
| - motion.animate(this.nightToDay) |
| 85 | + timeline.play() |
116 | 86 | } else {
|
117 |
| - motion.animate(this.dayToNight) |
| 87 | + timeline.reverse() |
118 | 88 | }
|
119 | 89 | })
|
120 | 90 | },
|
|
0 commit comments