Skip to content

Instantly share code, notes, and snippets.

@manngo
Last active December 23, 2020 04:03
Show Gist options
  • Save manngo/e88e769b1911fc694207888f3e52b9e1 to your computer and use it in GitHub Desktop.
Save manngo/e88e769b1911fc694207888f3e52b9e1 to your computer and use it in GitHub Desktop.
Untitled
body {
font-family: sans-serif;
}
ul#tabs {
list-style-type: none;
display: flex;
flex-direction: row;
padding: 1em;
border: thin solid #ccc;
box-sizing: border-box;
}
ul#tabs>li {
border: thin solid #ccc;
padding: .5em;
box-sizing: border-box;
}
li[draggable] {
background-color: #f8f8f8;
cursor: move;
user-select: none;
}
ul#tabs>li.dragging {
border-color: red;
}
ul#tabs>li.dragover-before {
border-left: thick solid red;
}
ul#tabs>li.dragover-after {
border-right: thick solid green;
}
<ul id="tabs">
<li>Apple</li>
<li>Banana</li>
<li>Cherry</li>
<li>Date</li>
<li>Elderberry</li>
</ul>
document.querySelectorAll('span.handle').forEach(span=>{
doStretch(span)
});
function doStretch(span) {
span.addEventListener('mousedown',stretch);
var previous=span.previousElementSibling;
var next=span.nextElementSibling;
function stretch(event) {
var width=parseInt(getComputedStyle(previous).width);
var x=event.clientX;
document.addEventListener('mousemove',goHorizontal);
document.addEventListener('mouseup',stop);
function goHorizontal(event) {
previous.style.width=width+event.clientX-x+'px';
previous.style.pointerEvents=next.style.pointerEvents='none';
}
function stop(event) {
document.removeEventListener('mousemove',goHorizontal);
document.removeEventListener('mouseup',stop);
previous.style.pointerEvents=next.style.pointerEvents='auto';
}
}
}
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"","page":"css"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment