title: Taro.createSelectorQuery()

sidebar_label: createSelectorQuery

Returns a SelectorQuery object instance. In a custom component or a page that contains a custom component, use this.createSelectorQuery() instead.

Reference

Type

  1. () => SelectorQuery

Parameters

Sample Code

  1. const query = Taro.createSelectorQuery()
  2. query.select('#the-id').boundingClientRect()
  3. query.selectViewport().scrollOffset()
  4. query.exec(function(res){
  5. res[0].top // The upper boundary coordinate of the #the-id node
  6. res[1].scrollTop // The vertical scroll position of the display area
  7. })

API Support

API WeChat Mini-Program H5 React Native
Taro.createSelectorQuery ✔️ ✔️