scroll-view组件 实现滚动到底部

method

scrollToBottom() {
  uni.$emit('scroll-to-bottom');
  var height = uni.getSystemInfoSync().windowHeight;
  var query = uni.createSelectorQuery();
  query.select('#scroll-view').boundingClientRect();
  query.exec((res) => {
    uni.pageScrollTo({
      scrollTop: res[0].height - height
    });
  });
}

或者

通过pageScrollTo方法

scrollToBottom() {
				// 获取屏幕高度
				var height = uni.getSystemInfoSync().windowHeight;
				// 滚动到页面的目标位置(单位px)
				uni.pageScrollTo({
					scrollTop: height
				})
			},

或者

通过监听window的scroll事件

scrollToBottom() {
				// 触发 时间
				uni.$emit('scroll-to-bottom');
				// 获取屏幕高
				var height = document.documentElement.scrollHeight || document.body.scrollHeight;
				// 滚动到底部
				window.scrollTo(0, height);
			},

 onLoad

onLoad() {
  uni.$on('scroll-to-bottom', this.scrollToBottom);
}

猜你喜欢

转载自blog.csdn.net/u013302168/article/details/132006817