Adds the request for querying the node layout position (in pixels) relative to the display area. This feature is similar to getBoundingClientRect of DOM. It returns SelectorQuery of NodesRef.
Taro.createSelectorQuery().select('#the-id').boundingClientRect(function(rect){ rect.id // The ID of the node rect.dataset // The dataset of the node rect.left // The left boundary coordinate of the node rect.right // The right boundary coordinate of the node rect.top // The upper boundary coordinate of the node rect.bottom // The lower boundary coordinate of the node rect.width // The width of the node rect.height // The height of the node }).exec()
Taro.createSelectorQuery().selectAll('.a-class').boundingClientRect(function(rects){ rects.forEach(function(rect){ rect.id // The ID of the node rect.dataset // The dataset of the node rect.left // The left boundary coordinate of the node rect.right // The right boundary coordinate of the node rect.top // The upper boundary coordinate of the node rect.bottom // The lower boundary coordinate of the node rect.width // The width of the node rect.height // The height of the node }) }).exec()
Taro.createSelectorQuery().select('.the-video-class').context(function(res){ console.log(res.context)// The Context object of the node. If the selected node is a <video> component, the VideoContext object is returned. }).exec()
Obtains the information about the node. The fields to be obtained are specified in fields. The selectorQuery of nodesRef is returned.
Note
computedStyle has a higher priority than size. When width/height is specified and "size: true" is passed in computedStyle, the width/height obtained by computedStyle is returned first.
Taro.createSelectorQuery().select('#the-id').fields({ dataset:true, size:true, scrollOffset:true, properties:['scrollX','scrollY'], computedStyle:['margin','backgroundColor'], context:true, },function(res){ res.dataset // The dataset of the node res.width // The width of the node res.height // The height of the node res.scrollLeft // The horizontal scroll position of the node res.scrollTop // The vertical scroll position of the node res.scrollX // The current value of the node's scroll-x property res.scrollY // The current value of the node's scroll-y property // Return the specified style name res.margin res.backgroundColor res.context // The Context object of the node }).exec()
Taro.createSelectorQuery().selectViewport().scrollOffset(function(res){ res.id // The id of the node res.dataset // The dataset of the node res.scrollLeft // The horizontal scroll position of the node res.scrollTop // The vertical scroll position of the node }).exec()
Specifies the style name list and returns the current value of the node style name
context
boolean
No
Indicates whether to return the Context object of the node
dataset
boolean
No
Indicates whether to return the node dataset
id
boolean
No
Indicates whether to return the node ID
mark
boolean
No
Specifies whether to return the node mark
node
boolean
No
Specifies whether to return the Node instance corresponding to the node.
properties
string[]
No
Specifies the property name list and returns the current property value of the node property name (only the general property values listed in the component document can be obtained, and "id class style" and the property values bound to events cannot be obtained)
rect
boolean
No
Indicates whether to return the node layout position (leftrighttopbottom)
scrollOffset
boolean
No
Indicates whether to return the node's scrollLeft and scrollTop. The node must be scroll-view or viewport.
size
boolean
No
Indicates whether to return the node size (width and height)