Подскажите, пожалуйста, почему не ресейзится размер колонок при перетягивании хендлера? Код ниже.
resizeColumns()
function resizeColumns() {
var wrapper = document.querySelector('.row');
var box = null;
var isHandlerDragging = false;
var boxAminWidth = 60;
var new_width = 0,
current_width = 0;
document.addEventListener('mousedown', function(e) {
// If mousedown event is fired from .handler, toggle flag to true
if (e.target.classList.contains('drag-handler')) {
isHandlerDragging = true;
box = e.target;
}
});
document.addEventListener('mousemove', function(e) {
// Don't do anything if dragging flag is false or
if (!isHandlerDragging) {
return false;
}
// save the current box width
current_width = window.getComputedStyle(box).width;
console.log('current_width :', current_width);
// check the minimum width
if ((new_width = e.clientX - box.offsetLeft - 8) >= boxAminWidth) {
box.style.width = new_width + 'px';
console.log('new_width :', new_width);
}
// make sure the boxs dont go past the wrapper, aka: the overflow effect
//if they do, we recover the last width of the current box to keep the boxs inside the wrapper.
if (wrapper.lastElementChild.offsetLeft + wrapper.lastElementChild.offsetWidth > wrapper.offsetWidth) {
box.style.width = current_width;
}
});
document.addEventListener('mouseup', function(e) {
// Turn off dragging flag when user mouse is up
isHandlerDragging = false;
});
}
.row {
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;
}
.col {
-ms-flex-preferred-size: 0;
flex-basis: 0;
-ms-flex-positive: 1;
flex-grow: 1;
max-width: 100%;
padding: 20px;
}
.position-relative {
position: relative !important;
}
.row .panel {
/* Allow box to grow and shrink, and ensure they are all equally sized */
/* flex: 1 1 auto;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
flex-grow: 0;
flex-shrink: 0;
*/
}
.panel:first-child::after {
content: "";
position: absolute;
top: 50%;
right: -5px;
z-index: 999;
transform: translateY(-50%);
display: block;
width: 10px;
height: 100px;
border-radius: 10px;
background: #f1f1f1;
box-shadow: inset rgba(0, 0, 0, .5) -3px -3px 8px, inset rgba(255, 255, 255, .9) 3px 3px 8px, rgba(0, 0, 0, .8) 3px 3px 8px -3px;
cursor: ew-resize;
flex: 0 0 auto;
}
<div class="row">
<div class="panel position-relative drag-handler col">
Cras sagittis. Suspendisse nisl elit, rhoncus eget, elementum ac, condimentum eget, diam. Ut leo. Praesent blandit laoreet nibh.
</div>
<div class="panel position-relative col">
Cras sagittis. Suspendisse nisl elit, rhoncus eget, elementum ac, condimentum eget, diam. Ut leo. Praesent blandit laoreet nibh.
</div>
</div>
row
потрите стильflex-wrap: wrap;
, а<div class="panel... col">
удалите классcol
.