-
-
Save fport/744e3c50869c79ed1bdc974964aca272 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeResizableDiv(div) { | |
const element = document.querySelector(div); | |
const resizers = document.querySelectorAll(div + ' .resizer') | |
for (let i = 0;i < resizers.length; i++) { | |
const currentResizer = resizers[i]; | |
currentResizer.addEventListener('mousedown', function(e) { | |
currentResizer.addEventListener('mousemove', resize) | |
}) | |
function resize(e) { | |
if (currentResizer.classList.contains('bottom-right')) { | |
element.style.width = e.pageX - element.getBoundingClientRect().left + 'px'; | |
} | |
} | |
} | |
} | |
makeResizableDiv('.resizable') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment