I have a layout in which the sidebar is resizable. I have done that using Javascript. But I want it to have a maximum and minimum value of resize. I have done that for the sidebar part by setting the max-width and min-width for the sidebar. But the problem is that main area goes decreasing(when expanding) even though the sidebar has been limited using max-width. I have been adding margin-left property to the main area according to the cursor pointer movement (using js ). But there is no property which allows us to set the maximum or minimum margin-left. How can I achieve this. Can anybody suggest any workaround to this ?
Js Fiddle - The whole code - https://jsfiddle.net/pdo4yjmg/
Please try to expand above 400px in the fiddle result , you can see the problem there ( 400px is the max-width )
Js part -
var element = document.getElementById('resizable');
if (element) {
var resizer = document.createElement('div');
resizer.className = 'draghandle';
resizer.style.width = '6px';
resizer.style.height = '100vh';
element.appendChild(resizer);
resizer.addEventListener('mousedown', initResize, false);
}
function initResize(e) {
window.addEventListener('mousemove', Resize, false);
window.addEventListener('mouseup', stopResize, false);
document.getElementById("mainArea").classList.add('marginLeft')
}
function Resize(e) {
element.style.width = (e.clientX - element.offsetLeft) + 'px';
document.getElementById("mainArea").style.marginLeft = (e.clientX - element.offsetLeft) + 'px';
}
function stopResize(e) {
window.removeEventListener('mousemove', Resize, false);
window.removeEventListener('mouseup', stopResize, false);
}