1

With CSS' resize rule, one can allow an element to be resized like so:

.someClass {
  resize: vertical/horizontal/both
}

However, I'm unable to find a way to detect an element is being resized.

HTML' Drag and Drop API has built-in events to detect dragging which are documented here.

Is there a similar way I can detect when an element is being dragged, or make my own version?

Nivyan
  • 119
  • 12
  • 1
    @yousoumar This might help with some of the more complicated things I want to do. I'm surprised it wasn't one of the suggested similar questions when I was creating the question/post. – Nivyan Jul 28 '22 at 09:07

1 Answers1

2

You need to get the element by a selector. For example:

const element = document.querySelector('.someClass');

And then you can use resizeObserver:

const resizeObserver = new ResizeObserver((entries) => {
  for (let entry of entries) {
     console.log(entry)
  }
  console.log('Size changed');
  
});

resizeObserver.observe(element);

For more resources: https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver

Youssouf Oumar
  • 29,373
  • 11
  • 46
  • 65
Mina
  • 14,386
  • 3
  • 13
  • 26