NodesRef.scrollOffset
Introduction
Adds a scroll position query request for a node (unit: pixels). The node must be a scroll-view or viewport. The return value is the selectorQuery
corresponding to the nodesRef
.
Parameters
Function callback
Explanation of the callback return parameters
In the returned node information, the scroll position of each node is described using the scrollLeft
and scrollTop
fields. If a callback function is provided, after executing the exec
method of selectQuery
, the node information will be returned in the callback.
Parameter | Type | Description |
---|---|---|
scrollLeft | Number | Node's horizontal scroll position |
scrollTop | Number | Node's vertical scroll position |
Sample Code
Page({
data: {
appear: false,
},
onReady() {
this.intersectionObserver = dlt.createIntersectionObserver();
this.intersectionObserver
.relativeTo('.scroll-view')
.observe('.ball', (res) => {
console.log('observe', res);
this.setData({ appear: res.intersectionRatio > 0 });
});
},
getNodeRef() {
dlt
.createSelectorQuery()
.select('.scroll-view')
.scrollOffset((res) => {
console.log('scrollOffset:', res);
})
.exec();
},
});