-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresize.js
More file actions
50 lines (40 loc) · 1.59 KB
/
resize.js
File metadata and controls
50 lines (40 loc) · 1.59 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
// resize.js
const panel1 = document.getElementById('panel1');
const panel2 = document.getElementById('panel2');
const resizer = document.querySelector('.resizer');
const container = document.querySelector('.container');
let originalX = 0;
let originalWidth1 = 0;
let originalWidth2 = 0;
let maxWidth1 = 0;
let minWidth1 = 0;
function resize(e) {
let widthChange = e.pageX - originalX;
let newWidth1 = originalWidth1 + widthChange;
if (newWidth1 < minWidth1) {
newWidth1 = minWidth1;
} else if (newWidth1 > maxWidth1) {
newWidth1 = maxWidth1;
}
panel1.style.flexBasis = newWidth1 + 'px';
panel2.style.flexBasis = (container.offsetWidth - newWidth1) + 'px';
updateDimensions();
}
function stopResize() {
panel1.classList.remove('no-select');
panel2.classList.remove('no-select');
panel2.classList.remove('resizing'); // Remove resizing class here
document.removeEventListener('mousemove', resize);
document.removeEventListener('mouseup', stopResize);
}
resizer.addEventListener('mousedown', function (e) {
originalX = e.pageX;
originalWidth1 = panel1.offsetWidth;
originalWidth2 = panel2.offsetWidth;
maxWidth1 = container.offsetWidth - minWidth1;
panel1.classList.add('no-select');
panel2.classList.add('no-select');
panel2.classList.add('resizing'); // Add resizing class here
document.addEventListener('mousemove', resize);
document.addEventListener('mouseup', stopResize);
});