uniapp弹幕滚动到底部

发布的弹幕至于最底部

在这里插入图片描述

<template>
	<view class="" style="position: fixed;bottom: 120rpx;left:0;rigth:0;background-color: #000;">
		<!-- scroll-with-animation 在设置滚动条位置时使用动画过渡 
			scroll-into-view值应为某子元素id(id不能以数字开头)。设置哪个方向可滚动,则在哪个方向滚动到该元素 
			在scroll-view添加scroll-into-view属性  在他的子元素添加id  这个属性和id一致就会滚动到该元素
		-->
		<scroll-view class="pl-3" scroll-y="true" style="width:520rpx;height: 300rpx;;"
			:scroll-into-view="scrollIntoView" scroll-with-animation :show-scrollbar="false" >
			<view :id="'danmu'+item.id" v-for="item in list" :key="item.id"
				class="mt-1  flex  justify-start  align-start p-2" style="background-color: rgba(255,255 ,255, 0.5);">
				<text class="text-danger font-md">{{item.name}}</text>
				<text class="text-danger font-md">{{item.content}}</text>
			</view>
		</scroll-view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				scrollIntoView: '',
				list: []
			}
		},
		mounted() {
			let id = 1;
			setInterval(() => {
				this.list.push({
					id: id,
					name: '昵称' + id,
					content: '内容 ' + id
				})
				this.bottom();
				id++
			}, 1000)

		},
		onLoad() {

		},
		methods: {
			bottom() {
				setTimeout(() => {
					let len = this.list.length;
					if (len > 0 && this.list[len - 1]) {
						this.scrollIntoView = 'danmu' + this.list[len - 1].id
					}
				}, 200)
			}

		}
	}
</script>

<style>
	.mt-1 {
		margin-top: 10rpx;
	}

	.rounded {
		border-radius: 8rpx;
	}

	.pl-3 {
		padding-left: 30rpx;
	}

	.p-2 {
		padding: 20rpx;
	}

	.text-white {
		color: #ffffff;
	}

	.text-danger {
		color: #dc3545;
	}

	.font-md {
		font-size: 35rpx !important;
	}

	.flex {
		/* #ifndef APP-PLUS-NVUE */
		display: flex !important;
		/* #endif */
		flex-direction: row;
	}

	.justify-start {
		justify-content: flex-start;
	}

	.align-start {
		align-items: flex-start;
	}
</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值