intersection-observer.js 556 B

1234567891011121314151617181920212223242526
  1. Page({
  2. onShareAppMessage() {
  3. return {
  4. title: 'WXML节点布局相交状态',
  5. path: 'page/API/pages/intersection-observer/intersection-observer'
  6. }
  7. },
  8. data: {
  9. appear: false
  10. },
  11. onLoad() {
  12. this._observer = wx.createIntersectionObserver(this)
  13. this._observer
  14. .relativeTo('.scroll-view')
  15. .observe('.ball', (res) => {
  16. console.log(res)
  17. this.setData({
  18. appear: res.intersectionRatio > 0
  19. })
  20. })
  21. },
  22. onUnload() {
  23. if (this._observer) this._observer.disconnect()
  24. }
  25. })