-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
117 lines (71 loc) · 2.78 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const notifications = document.querySelectorAll(".notifications")
const dots = document.querySelectorAll(".notificationsText_point");
const readButton = document.querySelector(".divNotification_readButton");
const notificationNumber = document.querySelector(".divNotification_number");
let random = Math.floor(Math.random() * (7-1) + 1) ;
createNotifications(random);
let unreadNotifications = searchNotifications();
notificationNumber.textContent = unreadNotifications;
hoverNotifications();
function createNotifications(number){
for(let i= number ; i<notifications.length ;i++){
notifications[i].style.backgroundColor = "hsl(0, 0%, 100%)";
dots[i].style.display = "none";
}
}
readButton.addEventListener("mouseover",(e)=>{
e.target.style.color="hsl(219, 85%, 26%)";
});
readButton.addEventListener("mouseleave",(e)=>{
e.target.style.color="hsl(219, 12%, 42%)";
})
readButton.addEventListener("click",(e)=>{
readAllNotifications();
//let unreadCount = searchNotifications();
let unreadCount = searchNotifications();
notificationNumber.textContent = unreadCount;
notificationNumber.style.backgroundColor = "hsl(219, 14%, 63%)";
})
function readAllNotifications(){
for(let i= 0 ; i<notifications.length ;i++){
notifications[i].style.backgroundColor = "hsl(0, 0%, 100%)";
dots[i].style.display = "none";
}
}
function searchNotifications(){
let readCount = 0 ;
for(let i = 0 ; i < dots.length;i++){
if(dots[i].style.display == "none"){
readCount++;
}
}
let unreadCount = notifications.length - readCount;
return unreadCount;
}
function hoverNotifications(){
let countDisplay = 0 ;
for(let i = 0; i < notifications.length;i++){
notifications[i].addEventListener("mouseover",(e)=>{
notifications[i].style.backgroundColor= "hsl(205, 33%, 90%)" ;
dots[i].style.display = "none";
countDisplay = countActive();
let unreadNotifications = notifications.length - countDisplay;
notificationNumber.textContent = unreadNotifications;
if(unreadNotifications == 0){
notificationNumber.style.backgroundColor = "hsl(219, 14%, 63%)";
}
})
notifications[i].addEventListener("mouseleave",(e)=>{
notifications[i].style.backgroundColor ="white";
})
}
}
function countActive(){
let countDisplay = 0;
for(let j = 0 ; j<notifications.length;j++){
if(dots[j].style.display=="none"){
countDisplay = countDisplay+1;
}
}
return countDisplay;
}