-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (59 loc) · 1.92 KB
/
index.js
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
const hour=document.querySelector('.hour');
const min=document.querySelector('.min');
const sec=document.querySelector('.sec');
const time=document.querySelector('.time');
const rotate=6;
const setAnalog= () =>{
let day =new Date();
let h=day.getHours()*30;
let m=day.getMinutes()*rotate;
let s=day.getSeconds()*rotate;
hour.style.transform=`rotateZ(${h+m/12}deg)`;
min.style.transform=`rotateZ(${m}deg)`;
sec.style.transform=`rotateZ(${s}deg)`;
// console.log(5)
};
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const d=["Sunday","Monday","tuesday","wednesday","thursday","friday","saturday"];
const setTime =()=>{
let day =new Date();
let hh=day.getHours();
let mm=day.getMinutes();
let ss=day.getSeconds();
let days=d[day.getDay()];
let month = months[day.getMonth()];
let date=day.getDate();
var ampm= 'AM';
if(hh>12){
hh=hh-12;
ampm= 'PM';
}
time.innerHTML=`
<h1 class=set-time>${hh}:${mm}:${ss} ${ampm}<h1>
<div class=dates>
<h3 class=set-date>${days} , ${month}<h3>
<h3 class=dat>${date}</h3>
</div>
`
}
setAnalog();
setTime();
setInterval(setAnalog,1000);
setInterval(setTime,1000);
const switchBtn=document.getElementsByClassName('change-mode')[0];
const switchMode =(evt) =>{
if(switchBtn.textContent=== "Dark Mode"){
switchBtn.textContent="Light Mode";
document.documentElement.classList.toggle("dark");
}
else{
switchBtn.textContent="Dark Mode";
document.documentElement.classList.toggle("dark");
}
};
switchBtn.addEventListener("click",switchMode,false);
let themeNow ="Dark Mode"
if(themeNow){
document.documentElement.setAttribute("data-theme",themeNow);
switchBtn.textContent=themeNow;
}