Essentially i want to resize the green box by dragging the blue thing.
I'm trying to use OffsetLeft
but is not working. also the drag event doesn't fire in Firefox.
And i have the code here: jsbin link
<div id="parent">
<div draggable="true" id="child" ondrag="dragging(event)" ></div>
</div>
<script>
const parent = document.getElementById('parent');
const child = document.getElementById('child');
function dragging(event) {
console.log("dragging");
parent.style.width = child.offsetLeft;
}
</script>
and css:
/* green box */
#parent{
position:absolute; -- notice the parent is absolute positioned. (not sure if it has an impact on how it works - but i need it to be absolute.
top: 100;
left: 100;
background-color: green;
height: 100px;
width: 100px;
display: flex;
justify-content: flex-end;
}
/* blue bar */
#child{
width: 5px;
background-color: blue;
cursor: e-resize;
}
So how can i do this, and also be cross-browser compatible
?
I need a html5 + js
solution - because i will use the logic for another programming language called elm
. I can only read stuff form the DOM, not mutate it. So I can't work with already built libraries like Jquery.
Thanks for your interest.
child.offsetLeft + 'px';
– PreponderanceoffsetLeft
at all - it's counter intuitive - i need a different approach. – Longheadedevent.pageX
... posted an answer and is now checking why FF won't play along – Preponderance