【css】动画重置

列表循环

需求

左侧切换同时右侧重置轮播
在这里插入图片描述
右侧轮播css实现

.active {
	animation: scollTop 30s linear 0s infinite;
	-webkit-animation: scollTop 30s linear 0s infinite;
}

/* 动画方法 */
@keyframes scollTop {
	from {
		top: 0;
	}
	to {
		top: -100%;
	}
}
@-webkit-keyframes scollTop {
	from {
		top: 0;
	}
	to {
		top: -100%;
	}
}

通过css无法实现动画的重置,无论左边在哪个区域中,右侧滚动都接着上一个滚动部位滚动;所以只能通过js实现

document.querySelector(".scroll").className = "scroll";
window.requestAnimationFrame(function(time) {
  document.querySelector(".scroll").className = "scroll active";
});

requestAnimationFrame

requestAnimationFrame/setTimeout/setInterval这三个方法都属于浏览器的window对象的方法,在过去只持支定时器setTimeout()和它setInterval()方法, requestAnimationFrame()新增的一个方法,可以更好的服务于2Dcanvas动画、WebGL动画等方面。

setTime/setInterval 都有清除定时器的方法
clearTimeout() / clearInterval()
requestAnimationFrame 也有自己的清除方法
cancelAnimationFrame()

requestAnimationFrame是浏览器用于定时循环操作的一个接口,类似于setTimeout,主要用途是按帧对网页进行重绘。
requestAnimationFrame是宏任务,在主线程执行
requestAnimationFrame参数是一个回调函数,这个回调函数会在浏览器重绘之前调用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值