Sign up (with export icon)

ResizeObserver

Api-class icon class

A helper class which instances allow performing custom actions when native DOM elements are resized.

const editableElement = editor.editing.view.getDomRoot();

const observer = new ResizeObserver( editableElement, entry => {
	console.log( 'The editable element has been resized in DOM.' );
	console.log( entry.target ); // -> editableElement
	console.log( entry.contentRect.width ); // -> e.g. '423px'
} );
Copy code

It uses the native DOM resize observer under the hood.

Properties

Static properties

Methods

  • Chevron-right icon

    constructor( element, callback )

    Creates an instance of the ResizeObserver class.

    Parameters

    element : Element

    A DOM element that is to be observed for resizing. Note that the element must be visible (i.e. not detached from DOM) for the observer to work.

    callback : ( entry: ResizeObserverEntry ) => void

    A function called when the observed element was resized. It passes the ResizeObserverEntry object with information about the resize event.

  • Chevron-right icon

    destroy() → void

    Destroys the observer which disables the callback passed to the constructor.

    Returns

    void

Static methods

  • Chevron-right icon

    _addElementCallback( element, callback ) → void
    Lock icon privatestatic

    Registers a new resize callback for the DOM element.

    Parameters

    element : Element
    callback : ( entry: ResizeObserverEntry ) => void

    Returns

    void
  • Chevron-right icon

    _createObserver() → void
    Lock icon privatestatic

    Creates the single native observer shared across all ResizeObserver instances.

    Returns

    void
  • Chevron-right icon

    _deleteElementCallback( element, callback ) → void
    Lock icon privatestatic

    Removes a resize callback from the DOM element. If no callbacks are left for the element, it removes the element from the native observer.

    Parameters

    element : Element
    callback : ( entry: ResizeObserverEntry ) => void

    Returns

    void
  • Chevron-right icon

    _getElementCallbacks( element ) → undefined | null | Set<( entry: ResizeObserverEntry ) => void>
    Lock icon privatestatic

    Returns are registered resize callbacks for the DOM element.

    Parameters

    element : Element

    Returns

    undefined | null | Set<( entry: ResizeObserverEntry ) => void>