Skip to main content

bn.createIntersectionObserver

createIntersectionObserver(component, options?): IntersectionObserver

description Creates and returns a IntersectionObserver Object instance. In a custom component or a page that contains it, you should use the this.createIntersectionObserver([options]) To replace.

remark support from jssdk > 4.0.0

example

Page({ onLoad() {  const observer = bn.createIntersectionObserver(this, {     thresholds: [0.1]  })this._observer.relativeTo('.container').observe('.start', res => {   console.log('createIntersectionObserver start: ', res)})

Parameters

NameType
componentComponentInstance
options?Options

Returns

IntersectionObserver

ComponentInstance#

Ƭ ComponentInstance: Object

Type declaration

NameTypeDescription
idstringComponent id

Options#

Ƭ Options: Object

Type declaration

NameTypeDescription
thresholdsnumber[]An array of values containing all thresholds. @default [0]
initialRationumberThe initial intersection ratio, which triggers a listener callback if the intersection ratio detected when called is not equal to this value and reaches a threshold. @default 0
observeAllbooleanWhether multiple target nodes are observed simultaneously (instead of one), if set to true ,observe of targetSelector Multiple nodes will be selected (Note: Selecting too many nodes at the same time will affect rendering performance) @default false

Class: IntersectionObserver#

NameTypeDescription
_componentComponentInstance
_optionsOptions
_relativeInfoRelativeInfo[]
_observerIdnull | number | ""
disconnectedboolean
_rendererIdundefined | number
callbackObserverCallback
relativeTo(selector, margins?): IntersectionObserverUse the selector to specify a node as one of the reference ranges
relativeToViewport(margins): IntersectionObserverSpecify the page display area as one of the reference areas
observe(targetSelector, callback): undefined | IntersectionObserverSpecify the target node and start listening for changes in the intersection state parameter
disconnect(): voidStop listening. The callback function will no longer trigger

relativeTo#

relativeTo(selector, margins?): IntersectionObserver

Use the selector to specify a node as one of the reference ranges

Parameters

NameType
selectornull | string
margins?Partial<{ left: number ; right: number ; top: number ; bottom: number }>

Returns

IntersectionObserver


relativeToViewport#

relativeToViewport(margins): IntersectionObserver

Specify the page display area as one of the reference areas

Parameters

NameType
marginsPartial<{ left: number ; right: number ; top: number ; bottom: number }>

Returns

IntersectionObserver


observe#

observe(targetSelector, callback): undefined | IntersectionObserver

Specify the target node and start listening for changes in the intersection state parameter

Parameters

NameType
targetSelectorstring
callbackObserverCallback

Returns

undefined | IntersectionObserver


disconnect#

disconnect(): void

Stop listening. The callback function will no longer trigger

Returns

void

Class: IntersectionObserver#

NameTypeDescription
_componentComponentInstance
_optionsOptions
_relativeInfoRelativeInfo[]
_observerIdnull | number | ""
disconnectedboolean
_rendererIdundefined | number
callbackObserverCallback
relativeTo(selector, margins?): IntersectionObserverUse the selector to specify a node as one of the reference ranges
relativeToViewport(margins): IntersectionObserverSpecify the page display area as one of the reference areas
observe(targetSelector, callback): undefined | IntersectionObserverSpecify the target node and start listening for changes in the intersection state parameter
disconnect(): voidStop listening. The callback function will no longer trigger

relativeTo#

relativeTo(selector, margins?): IntersectionObserver

Use the selector to specify a node as one of the reference ranges

Parameters

NameType
selectornull | string
margins?Partial<{ left: number ; right: number ; top: number ; bottom: number }>

Returns

IntersectionObserver


relativeToViewport#

relativeToViewport(margins): IntersectionObserver

Specify the page display area as one of the reference areas

Parameters

NameType
marginsPartial<{ left: number ; right: number ; top: number ; bottom: number }>

Returns

IntersectionObserver


observe#

observe(targetSelector, callback): undefined | IntersectionObserver

Specify the target node and start listening for changes in the intersection state parameter

Parameters

NameType
targetSelectorstring
callbackObserverCallback

Returns

undefined | IntersectionObserver


disconnect#

disconnect(): void

Stop listening. The callback function will no longer trigger

Returns

void

ObserverCallback#

Ƭ ObserverCallback: (res: Response) => void

Type declaration

▸ (res): void

Parameters

NameType
resResponse

Returns

void


Response#

Ƭ Response: Object

Type declaration

NameTypeDescription
boundingClientRectOmit<DOMRectReadOnly, "x" | "y" | "toJSON">Target boundary
datasetRecord<string, Any>Node Custom Data Properties
idnumber | stringNode id
intersectionRationumberIntersecting proportion. How much of the target element is currently visible within the root's intersection ratio, as a value between 0.0 and 1.0. https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry/intersectionRatio
intersectionRectOmit<DOMRectReadOnly, "x" | "y" | "toJSON">Boundary of intersecting region
relativeRectRectBoundary of reference area
timenumberTime Stamp for Intersection Detection

Any#

Ƭ Any: any


Rect#

Ƭ Rect: Object

Type declaration

NameTypeDescription
leftnumberLeft boundary
rightnumberRight boundary
topnumberUpper boundary
bottomnumberLower boundary