-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresize.js
More file actions
55 lines (46 loc) · 1.8 KB
/
Copy pathresize.js
File metadata and controls
55 lines (46 loc) · 1.8 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
const sidebarResize = document.querySelector('.sidebar-resize');
const sidebar = document.querySelector('.sidebar');
const collectionsResize = document.querySelector('.collections-resize');
const collections = document.querySelector('.collections');
let isResizing = false;
sidebarResize.addEventListener('mousedown', (e) => {
isResizing = true;
const initialX = e.clientX;
document.addEventListener('mousemove', resizeSidebar);
document.addEventListener('mouseup', stopResize);
function resizeSidebar(e) {
if (isResizing) {
const width = initialX - e.clientX;
const sidebarWidth = sidebar.offsetWidth;
const newWidth = sidebarWidth + width;
// const newWidth = width;
sidebar.style.width = `${newWidth}px`;
// viewport.style.width = `calc(100% - ${newWidth}px)`;
}
}
function stopResize() {
isResizing = false;
document.removeEventListener('mousemove', resizeSidebar);
document.removeEventListener('mouseup', stopResize);
}
});
collectionsResize.addEventListener('mousedown', (e) => {
isResizing = true;
const initialY = e.clientY;
document.addEventListener('mousemove', resizeCollections);
document.addEventListener('mouseup', stopResize);
function resizeCollections(e) {
if (isResizing) {
const height = initialY - e.clientY;
const collectionsHeight = sidebar.offsetHeight;
const newHeight = height;
collections.style.height = `${e.clientY}px`;
// viewport.style.width = `calc(100% - ${newWidth}px)`;
}
}
function stopResize() {
isResizing = false;
document.removeEventListener('mousemove', resizeCollections);
document.removeEventListener('mouseup', stopResize);
}
});