4***@qq.com
4***@qq.com
  • 发布:2024-05-19 14:42
  • 更新:2024-05-19 14:42
  • 阅读:273

【报Bug】uni.createIntersectionObserver 无效

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: 22621.3447

HBuilderX类型: 正式

HBuilderX版本号: 3.99

浏览器平台: Edge

浏览器版本: 124.0.2478.67

项目创建方式: HBuilderX

示例代码:

<template>
<!-- 这里有注释uni.createIntersectionObserver就失效 -->
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-title uni-common-mt">
{{appear ? '小球出现' : '小球消失'}}
</view>
<scroll-view class="scroll-view" scroll-y>
<view class="scroll-area">
<text class="notice">向下滚动让小球出现</text>
<view class="ball"></view>
</view>
</scroll-view>
</view>
</view>
</template>
<script>
let observer = null;
export default {
data() {
return {
appear: false,
title:'intersectionObserver'
}
},
onReady() {
observer = uni.createIntersectionObserver(this);
observer.relativeTo('.scroll-view').observe('.ball', (res) => {
if (res.intersectionRatio > 0 && !this.appear) {
this.appear = true;
} else if (!res.intersectionRatio > 0 && this.appear) {
this.appear = false;
}
})
},
onUnload() {
if (observer) {
observer.disconnect()
}
}
}
</script>
<style>
.scroll-view {
height: 400rpx;
background: #fff;
border: 1px solid #ccc;
box-sizing: border-box;
}

.scroll-area {  
    height: 1300rpx;  
    display: flex;  
    flex-direction: column;  
    align-items: center;  
}  

.notice {  
    margin-top: 150rpx;  
    margin: 150rpx 0 400rpx 0;  
}  

.ball {  
    width: 200rpx;  
    height: 200rpx;  
    background: #4cd964;  
    border-radius: 50%;  
}  

</style>

操作步骤:

代码如上

预期结果:

代码如上

实际结果:

代码如上

bug描述:

<template>之下有注释uni.createIntersectionObserver就失效, 或者 有page-meta节点也失效。

<template>  
    <!-- 这里有注释uni.createIntersectionObserver就失效 -->  
    <view>  
        <page-head :title="title"></page-head>  
        <view class="uni-padding-wrap uni-common-mt">  
            <view class="uni-title uni-common-mt">  
                {{appear ? '小球出现' : '小球消失'}}  
            </view>  
            <scroll-view class="scroll-view" scroll-y>  
                <view class="scroll-area">  
                    <text class="notice">向下滚动让小球出现</text>  
                    <view class="ball"></view>  
                </view>  
            </scroll-view>  
        </view>  
    </view>  
</template>
<template>  
    <page-meta root-font-size="16px"></page-meta>  
    <view>  
        <page-head :title="title"></page-head>  
        <view class="uni-padding-wrap uni-common-mt">  
            <view class="uni-title uni-common-mt">  
                {{appear ? '小球出现' : '小球消失'}}  
            </view>  
            <scroll-view class="scroll-view" scroll-y>  
                <view class="scroll-area">  
                    <text class="notice">向下滚动让小球出现</text>  
                    <view class="ball"></view>  
                </view>  
            </scroll-view>  
        </view>  
    </view>  
</template>
2024-05-19 14:42 负责人:无 分享
已邀请:

要回复问题请先登录注册