css3实现无缝滚动

10 篇文章 0 订阅

css3实现无缝滚动

横向滚动

<view class="move-box">
    <view class="move">
		<view class="item" v-for="(item, index) in 2" :key="index">
			{{index}}寒雨连江夜入吴,平明送客楚山孤,洛阳亲友如相问,一片冰心在玉壶。
		</view>
    </view>
</view>

.move-box {
	position: relative;
	width: 100%;
	white-space: nowrap;
	.move {
		position: absolute;
		top: 0;
		width: 1520rpx;
		overflow: hidden;
		white-space: nowrap; 
		animation: move 10s infinite linear normal;
	}
	.item {
		float: left;
		width: 760rpx;
		font-size: 26rpx;
	}
}
@keyframes move {
	0% { 
		left: 0;
	}
	100% {
		left: -760rpx;
	}
}

纵向滚动元素

<template>
	<view class="list">
		<view class="group">
			<view class="item" v-for="(item, index) in 6" :key="index">
				1*{{index}}
			</view>
			<view class="item" v-for="(item, index) in 6" :key="index">
				2*{{index}}
			</view>
		</view>
	</view>
</template>

.list {
	margin: 20px auto;
	position: relative;
	width: 300rpx;
	height: 300rpx;
	overflow: hidden;
	border: 1px solid red;
	.group {
		position: relative;
		width: 300rpx;
		animation: moveUp 5s linear infinite normal;
	}
}

@keyframes moveUp {
	0% {
		transform:translate3d(0, 0, 0);
	}

	100% {
		transform: translate3d(0, -300rpx, 0);
	}
}

注意:

  1. 移动的距离( 例left),要与每项(item)的宽度保持一致,来实现无缝滚动。
  2. 如果动态元素,宽度需要计算…
  3. 【可以不用完全的复制一份】动画位移的长度等于元素之和,当最后一个元素移出时,动画也正好完成。根据需要来填充空白部分(假设图片就放前面的那几张),当新一轮动画开始时,正好是开始的那几张图片,因此达到无缝循环效果。
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值