Skip to main content

Perceptor

Perceptor is the core class of this library that tracks visibility of target DOM elements. It coordinates a Scheduler, a chain of Spectators, and Subscribers to evaluate element viewability.

Perceptor offers configurable parameters (both global and per instance), runtime control over visibility monitoring via watch() and unwatch(), and native click event handling.

Constructor

new Perceptor(DOMElement, [options])
  • DOMElement (Element): Mandatory DOM Element to observe.
  • options (Object): Optional configuration overrides. See the Configuration page for details.

Usage Example

var perceptorInstance = new Perceptor(document.querySelector('#testdiv'));
perceptorInstance.watch();

Instance Methods

watch()

Triggers active observation mode. Must be called to start detecting viewability changes.

unwatch()

Disables active observation for this instance.

Instance Properties

PropertyTypeDescription
configObjectConfiguration options applicable to this instance.
elementElementThe target DOM Element under observation.
eventFunctionCallback executed when element is clicked.
spectatorChainSpectatorManagerSpectatorManager instance controlling spectator execution.
subscriberChainSubscriberManagerSubscriberManager instance handling notifications.
schedulerSchedulerActive Scheduler engine triggering evaluation cycles.