Say one has a div which is vertically resizable like a textarea as below. When the user resizes the div, I would like to run a javascript function, resizeHandler
below.
It seems like the resize
event is only for the document/window. And resize observer fires for all events, like say when the document is loading, it will fire resize observer events. So then I set a timeout to apply the resize observer after the page load, but the resize observer seems to remember historic resizes, and fires the previous resizes events.
Is there a clean way to run resizeHandler()
when the user resizes the div, and not for pageloading layout shifts?
function resizeHandler() {
console.log('the div was resized')
}
div {
resize: vertical;
height: 64px;
overflow-y: auto;
background-color:gray;
}
<div id="DIV" style="max-height:180px">This is a resizable div</div>
Note: I can't remove the style attribute of the div which sets the max-height
.