-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
87 lines (69 loc) · 2.66 KB
/
script.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const secondHand = document.querySelector('.second-hand');
const hourHand = document.querySelector('.hour-hand');
const minHand = document.querySelector('.min-hand');
const digitalSecond = document.querySelector('.seconds');
const digitalMinutes = document.querySelector('.minutes');
const digitalHour = document.querySelector('.hour');
const theYear = document.querySelector('.year');
const theMonth = document.querySelector('.month');
const theDay = document.querySelector('.day');
const theDayName = document.querySelector('.day-name');
function setDate(){
const now = new Date();
const seconds = now.getSeconds();
const secondsDegrees = ((seconds / 60) * 360) + 90;
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
digitalSecond.innerText = seconds.toString().padStart(2,'0');
const minutes = now.getMinutes();
const minutesDegrees = ((minutes / 60) * 360) + 90;
minHand.style.transform = `rotate(${minutesDegrees}deg)`;
digitalMinutes.innerText = minutes.toString().padStart(2,'0');
const hours = now.getHours();
const hourDegrees = ((hours / 12) * 360) + 90;
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
digitalHour.innerText = hours.toString().padStart(2,'0');
const day = now.getDate();
const month = now.getMonth();
const year = now.getFullYear();
const dayName = now.getDay();
theYear.innerText = year;
theDay.innerText = day;
theDayName.innerText = dayName;
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
for(let i = 0; i < months.length; i++){
if(month === i){
theMonth.innerText = months[i];
}
}
const days = ['Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
for(let i = 0; i < days.length; i++){
if(dayName === i){
theDayName.innerText = days[i];
}
}
}
setInterval(setDate, 1000);
setDate();
// For Dragging //
let x = 0;
let y = 0;
const ele = document.querySelector('#drag-canvas');
const mouseDown = function (e) {
x = e.clientX;
y = e.clientY;
ele.addEventListener('mousemove', mouseMove);
ele.addEventListener('mouseup', mouseUp);
}
const mouseMove = function(e){
const dx = e.clientX - x;
const dy = e.clientY - y;
ele.style.top = `${ele.offsetTop + dy}px`;
ele.style.left = `${ele.offsetLeft + dx}px`;
x = e.clientX;
y = e.clientY;
}
const mouseUp = function(e){
ele.removeEventListener('mousemove', mouseMove);
ele.removeEventListener('mouseup', mouseUp);
}
ele.addEventListener('mousedown', mouseDown);