scroll-view设置scrollTop:0时页面白屏

问题:当scroll-view滚动到一个位置,然后点击按钮让回到到顶部,会出现白屏。

请添加图片描述

<view class="container">
	<view class="main">
		<scroll-view 
			scroll-y="{{true}}" 
			scroll-top="{{scrollTop}}" 
			scroll-with-animation="{{false}}" 
			class="scroll-view">
			<view class="list">
				<view wx:for="{{list}}" wx:key="index" class="item" style="background: {{item.color}};">
					{{item.id}}
				</view>
			</view>
		</scroll-view>
	</view>
	<button bind:tap="handleClick">点击</button>
</view>
.container {
	display: flex;
	flex-direction: column;
	width: 100vw;
	height: 100vh;
	overflow: hidden;
}
.main{
	flex: 1;
	position: relative;
}
.scroll-view{
	position: absolute;
	left: 0;
	right: 0;
	top: 0;
	bottom: 0;
}
.item {
	flex-shrink: 0;
	height: 500rpx;
	font-size: 100rpx;
	text-align: center;
}
Page({

    /**
     * 页面的初始数据
     */
    data: {
        scrollTop: 0,
        list: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let list = this.getData(10);
        this.setData({
            list
        })
    },
    color() {
        this.r = Math.floor(Math.random() * 255);
        this.g = Math.floor(Math.random() * 255);
        this.b = Math.floor(Math.random() * 255);
        return 'rgba(' + this.r + ',' + this.g + ',' + this.b + ',0.8)';
    },
    getData(num) {
        const { list } = this.data;
        let arr = [];
        for (let i = list.length; i < num + list.length; i++) {
            let color = this.color()
            arr.push({
                id: i + 1,
                color
            });
        }
        return arr;
    },
    handleClick(){
        this.setData({
            scrollTop: 0
        });
    }
})

解决方案: 将scroll-with-animation 设置为true就可以解决该问题。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值