Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
74 lines (62 loc) · 1.69 KB
/
Copy pathscript.js
File metadata and controls
74 lines (62 loc) · 1.69 KB
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
// Scroll suave global
document.documentElement.style.scrollBehavior = "smooth";let color = document.getElementById('color');
let createBtn = document.getElementById('createBtn');
let list = document.getElementById('list');
createBtn.onclick = () => {
let newNote = document.createElement('div');
newNote.classList.add('note');
newNote.innerHTML = `
<span class="close">x</span>
<textarea
placeholder="Write Content..."
rows="10" cols="30"></textarea>`;
newNote.style.borderColor = color.value;
list.appendChild(newNote)
}
document.addEventListener('click', (event) => {
if(event.target.classList.contains('close')){
event.target.parentNode.remove();
}
})
let cursor = {
x: null,
y: null
}
let note = {
dom: null,
x: null,
y: null
}
document.addEventListener('mousedown', (event) => {
if(event.target.classList.contains('note')){
cursor = {
x: event.clientX,
y: event.clientY
}
note = {
dom: event.target,
x: event.target.getBoundingClientRect().left,
y: event.target.getBoundingClientRect().top
}
console.log(note)
}
})
document.addEventListener('mousemove', (event) => {
if(note.dom == null) return;
let currentCursor = {
x: event.clientX,
y: event.clientY
}
let distance = {
x: currentCursor.x - cursor.x,
y: currentCursor.y - cursor.y
}
note.dom.style.left = (note.x + distance.x) + 'px';
note.dom.style.top = (note.y + distance.y) + 'px';
note.dom.style.cursor = 'grab';
})
document.addEventListener('mouseup', () => {
if(note.dom == null) return;
note.dom.style.cursor = 'auto';
note.dom = null;
})