-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
74 lines (68 loc) · 2.46 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html data-theme="light">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
<title>Sass</title>
</head>
<body>
<div class="d-container">
<h1>Dark mode using Sass</h1>
<div class="form-check form-switch toggle-container">
<input class="form-check-input" type="checkbox" name="theme" id="switch" />
</div>
<p>Hi, in this tutorials I will show you how to make a dark mode for your website!</p>
</div>
<script>
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
let checkbox = document.querySelector('input[name=theme]');
checkbox.addEventListener('change', function (){
if (checkbox.checked == true) {
trans();
document.documentElement.setAttribute('data-theme', 'dark')
createCookie('darkmode', 'darkmodeisactive', 1);
}else{
trans();
document.documentElement.setAttribute('data-theme', 'light')
eraseCookie('darkmode')
}
});
if(readCookie('darkmode')){
checkbox.checked = true;
document.documentElement.setAttribute('data-theme', 'dark')
}else{
checkbox.checked = false;
document.documentElement.setAttribute('data-theme', 'light')
}
let trans = () => {
document.documentElement.classList.add('transition');
window.setTimeout( () => {
document.documentElement.classList.remove('transition')
}, 1000);
};
</script>
</body>
</html>