IntersectionObserver.observe

    String targetSelector, Function callback

    callback参数说明 监听相交状态变化的回调函数

    intersectionRect、boundingClientRect、relativeRect 结构说明

    属性类型说明
    leftnumber左边界
    rightnumber右边界
    topnumber上边界
    bottomnumber下边界

    示例

    请使用百度APP扫码

    图片示例

    IntersectionObserver.observe - 图3

    1. data: {
    2. data: ''
    3. },
    4. onReady() {
    5. swan.createIntersectionObserver(this, {
    6. })
    7. .observe('.ball', res => {
    8. this.setData('data', res.intersectionRect);
    9. console.log(res.intersectionRect.left); // 相交区域的左边界坐标
    10. console.log(res.intersectionRect.width); // 相交区域的宽度
    11. console.log(res.intersectionRect.height); // 相交区域的高度
    12. });
    13. }