美文网首页
抖音小程序开发

抖音小程序开发

作者: vavid | 来源:发表于2023-07-05 17:47 被阅读0次

开发者文档:

https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/component/overview

快捷搬砖:

1. 获取页面路由: getCurrentPages

// 获取当前页面路由:
const curIndex = getCurrentPages().length - 1
const curRoute = getCurrentPages()[curIndex].route

2. 判断dom滚动到可视区域:tt.createIntersectionObserver

onReady() {

    setTimeout(()=>{
      const intersectionObserver = this.createIntersectionObserver(this, {
        thresholds: [0],
        initialRatio: 0,
        observeAll: false,
      });
      // 针对当前页面中的id="content"的dom
      intersectionObserver.relativeToViewport().observe("#content", (res) => {
          const { 
            intersectionRatio,
            intersectionRect,
            boundingClientRect,
            relativeRect} = res;

          if (intersectionRatio > 0) {
            console.log('id=content 的盒子进入视线')
          }else if(intersectionRatio === 0){
            console.log('id=content 的盒子离开视线')
          }
      });
    }, 1000)
    
  },

注意:延迟执行在某些场景下是必要的

相关文章

网友评论

      本文标题:抖音小程序开发

      本文链接:https://www.haomeiwen.com/subject/oldkudtx.html