Skip to content

Commit 5e8f085

Browse files
committed
Update README
1 parent 5694235 commit 5e8f085

File tree

1 file changed

+79
-4
lines changed

1 file changed

+79
-4
lines changed

README.md

+79-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414

1515
<br>
1616

17-
1. ...
18-
2. ...
17+
1. Using CSS variables
18+
2. `background: rgb(255 255 255 / 50%)` instead of `rgba(255, 255, 255, 0.5)`
19+
3. Smooth scroll with `html { scroll-behavior: smooth };`
20+
4. Creating a [toggle switch](https://www.w3schools.com/howto/howto_css_switch.asp)
21+
5. Setting attributes on the root element (html)
22+
6. Using `document.documentElement`
1923

2024
<br>
2125

@@ -25,13 +29,84 @@
2529

2630
<br>
2731

28-
### Part 1
32+
### Creating the toggle switch
2933

3034
<br>
3135

32-
Bla bla
36+
**index.html**
37+
38+
```html
39+
<div class="theme-switch-wrapper">
40+
<!-- Text and icon -->
41+
<span id="toggle-icon">
42+
<span class="toggle-text">Light Mode</span>
43+
<i class="fas fa-sun"></i>
44+
</span>
45+
<!-- Switcher -->
46+
<label class="theme-switch">
47+
<input type="checkbox">
48+
<div class="slider round"></div>
49+
</label>
50+
</div>
51+
```
52+
53+
<br>
54+
55+
**style.css**
56+
57+
```css
58+
59+
```
60+
61+
<br>
62+
63+
**script.js**
64+
65+
<br>
66+
67+
Add event listener to the toggle switch. We use the change event.
68+
69+
```js
70+
const toggleSwitch = document.querySelector('input[type="checkbox"]');
71+
72+
// Switch Theme Dynamically
73+
//...
74+
75+
76+
// Event Listener
77+
toggleSwitch.addEventListener('change', switchTheme);
78+
```
79+
80+
<br>
81+
82+
We create function that dynamically changes the theme
83+
84+
```js
85+
// Switch Theme Dynamically
86+
function switchTheme(event) {
87+
if (event.target.checked) {
88+
document.documentElement.setAttribute('data-theme', 'dark');
89+
} else {
90+
document.documentElement.setAttribute('data-theme', 'light');
91+
}
92+
93+
}
94+
```
95+
96+
We use property `target.checked` to check if the switch toggle has been checked (show dark mode) or not (light mode).
97+
98+
1. We set the `data-theme` attribute at the highest level of the html
99+
2. `document.documentElement` returns the...
33100

34101
<br>
35102

36103
---
37104

105+
Background from [hero patterns](https://www.heropatterns.com/)
106+
107+
Illustrations from [Undraw](https://undraw.co/illustrations)
108+
109+
Icons from [FontAwesome](https://fontawesome.com/)
110+
111+
112+

0 commit comments

Comments
 (0)