Hi all,
First: a demo, to be viewed on desktop -Feature made to be disabled on mobile devices => https://test-play.softr.app/two-columns-draggable
Now the codes to insert.
I) In a custom code block, in my example, just below the hero block (reduce the padding top and bottom of this custom code block to not disturb your page design)
<div class="row">
<div class="column left-column">
<div class="draggable-border"></div>
<span id="tocolumn1"></span>
</div>
<div class="column right-column">
<div class="draggable-border"></div>
<span id="tocolumn2"></span>
</div>
</div>
II) In the header code of the page settings:
<style>
.column {
float: left;
}
.left-column {
width: 50%;
border-right: 1px solid #ebebeb;
position: relative;
}
.right-column {
width: 50%;
position: relative;
}
.draggable-border {
position: absolute;
top: 0;
width: 6px;
height: 100%;
cursor: col-resize;
z-index: 1;
background-color: #ebebeb;
border-radius: 4px;
}
.left-column .draggable-border {
right: -3px;
}
.right-column .draggable-border {
left: -3px;
}
.left-column:hover .draggable-border,
.right-column:hover .draggable-border {
background-color: #ddd;
}
.row:after {
content: "";
display: table;
clear: both;
}
@media screen and (max-width: 600px) {
.column {
width: 100%;
}
}
</style>
III) In the footer code of the page settings Replace #chart1 and #chart2 by the block ids you want
<script>
$("#chart1").insertAfter($("#tocolumn1"));
$("#chart2").insertAfter($("#tocolumn2"));
</script>
<script>
$(function() {
var dragging = false;
var leftColumn = $('.left-column');
var rightColumn = $('.right-column');
var border = $('.draggable-border');
border.mousedown(function(e) {
e.preventDefault();
dragging = true;
});
$(document).mouseup(function() {
dragging = false;
});
$(document).mousemove(function(e) {
if (dragging) {
var offset = e.pageX - leftColumn.offset().left;
var newLeftWidth = offset / leftColumn.parent().width() * 100;
var newRightWidth = 100 - newLeftWidth;
if (newLeftWidth < 30) {
rightColumn.css('pointer-events', 'none');
} else if (newRightWidth < 30) {
leftColumn.css('pointer-events', 'none');
} else {
leftColumn.css('pointer-events', 'auto');
rightColumn.css('pointer-events', 'auto');
leftColumn.css('width', newLeftWidth + '%');
rightColumn.css('width', newRightWidth + '%');
}
}
});
});
</script>
IMPORTANT: I made impossible to drag one or the other column if their width is below 30% of their original width. Otherwise it is going to be a disgusting design.
That being said, you can overwrite it by changing the value ‘30’ of these code lines:
if (newLeftWidth < 30) {
and
} else if (newRightWidth < 30) {
The look of the draggable border is fully customizable in this part of the code
.draggable-border {
position: absolute;
top: 0;
width: 6px;
height: 100%;
cursor: col-resize;
z-index: 1;
background-color: #ebebeb;
border-radius: 4px;
}
If you want to change the wifth of the .draggable-border you will also need to change this part of the code
.left-column .draggable-border {
right: -3px;
}
.right-column .draggable-border {
left: -3px;
}
Let’s take an example: you want the width of the .draggable-border to be 10px. You will need to change the -3px
to -5px
, otherwise two draggable borders will appear.