-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
95 lines (60 loc) · 2.42 KB
/
app.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
// Get items from the html document
const todoInput = document.querySelector('.todo-input');
const todoButton = document.querySelector('.todo-button');
const todoList = document.querySelector('.todo-list');
const fireIcon=document.querySelector('.fa-fire');
const colors= ['#003663','#090b16','linear-gradient(120deg,#1f4037,#99f2c8)','linear-gradient(120deg,#FF0099,#493240)']; //adding multiple background colors
//EVENT LISTNERS//
// create a click event to the buttons
todoButton.addEventListener('click',addTodo);
todoList.addEventListener('click',deleteCheck);
fireIcon.addEventListener('click',changeColor)
//FUNCTIONS//
// Add tasks implementation
function addTodo(e){
e.preventDefault() // prevents page from refreshing after submitting
const todoDiv= document.createElement('div'); //create a div tag
todoDiv.classList.add('todo'); //add a class todo to the div class
//LI//
const newTodo=document.createElement('li'); //create a list tag
newTodo.innerHTML=todoInput.value; //set value of list to user input value
newTodo.classList.add('todo-item');
todoDiv.appendChild(newTodo); //add list data to todDiv
// BUTTONS//
// Completed tasks implementation
const completeBtn = document.createElement('button');
completeBtn.innerHTML='<i class="fas fa-check"></i>';
completeBtn.classList.add('complete-btn');
todoDiv.appendChild(completeBtn);
const trashBtn = document.createElement('button');
trashBtn.innerHTML='<i class="fas fa-trash"></i>';
trashBtn.classList.add('trash-btn');
todoDiv.appendChild(trashBtn);
// APPEND TO LIST//
todoList.appendChild(todoDiv);
console.log(todoList);
todoInput.value=''; //set value of the input to empty after adding todo
}
function deleteCheck(e){
const itemh=e.target;
// DELETE BUTTON
if (itemh.classList[0]=='trash-btn'){
const itemParent=itemh.parentElement;
//Transition animation
itemParent.classList.add('fall');
itemParent.addEventListener('transitionend',function(){
itemParent.remove()
})
}
// COMPLETED BUTTON
if(itemh.classList[0]==='complete-btn'){
const itemParent= itemh.parentElement;
itemParent.classList.toggle('completed');
}
}
// background colors implementation
var i=0;
function changeColor(e){
i=i<colors.length-1?++i:0;
document.querySelector('body').style.background=colors[i];
}