Skip to content

@serenity-is/corelib / executeOnceWhenVisible

Function: executeOnceWhenVisible()

executeOnceWhenVisible(el, callback): number

Defined in: src/compat/layouttimer.ts:246

Executes a callback once when the element becomes visible. If the element is already visible (positive offsetWidth / offsetHeight), the callback is invoked immediately and null is returned. Otherwise registers via LayoutTimer.onShown and auto-unregisters after the first fire.

Parameters

el

Target element or array-like collection (first element is used).

HTMLElement | ArrayLike<HTMLElement>

callback

Function

Function to invoke when visible.

Returns

number

The LayoutTimer registration key, or null if already visible / element missing.

Deprecated

Prefer IntersectionObserver or ResizeObserver. Kept for legacy triggerLayoutOnShow compatibility.