uni-app实现公告文本超出从右向左循环滚动

<view class="right-left-scroll">
		<view 
			class="content" 
			:style="{'animation': `noticeAnimation ${time}s linear 1s infinite`}"
		>
			{{notice}}
		</view>
	</view>
export default {
		data() {
			return {
				notice: '空前折扣力度,专享福利大家快来抢利大家快快来抢购下dfdfdfddfdfdfd专享福利大家快来抢利大家快快来抢购下专享福利大家快来抢',
                time: 0,
			}
		},
		mounted() {
			let scroll_width = 0;
			const query = uni.createSelectorQuery().in(this);
			query.select('.right-left-scroll').boundingClientRect(data => {
				scroll_width = (data.width).toFixed(2);
			}).exec();
			
			query.select('.right-left-scroll .content').boundingClientRect(data => {
				if(data.width - scroll_width > 0) {
					this.time = (9 * data.width / scroll_width).toFixed(2);
				}
			}).exec();
		}
	}}
	}
.right-left-scroll {
		white-space: nowrap;
		overflow: hidden;
		
		.content {
			display: inline-block;
		}
	}
注意:只有在app.vue里面定义的keyframes才能在style里面使用
app.vue文件style中:

@keyframes noticeAnimation {
	from {
		transform: translateX(100rpx);
	}
	to {
		// transform: translateX(calc(-100% + 150px));
		transform: translateX(-100%);
	}
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值