,可以通过以下几种方式实现:
示例代码:
.animation-element {
animation-name: myAnimation;
animation-duration: 3s;
animation-iteration-count: infinite;
animation-play-state: running;
}
.animation-element.paused {
animation-play-state: paused;
}
window.addEventListener('load', function() {
var animationElement = document.querySelector('.animation-element');
animationElement.classList.add('paused');
});
推荐的腾讯云相关产品:无
示例代码:
<div class="animation-element"></div>
<script>
window.addEventListener('load', function() {
var animationElement = document.querySelector('.animation-element');
var animation = animationElement.animate([
{ transform: 'translateX(0)' },
{ transform: 'translateX(100px)' }
], {
duration: 3000,
iterations: Infinity
});
animation.pause();
});
</script>
推荐的腾讯云相关产品:无
示例代码(使用GSAP库):
<div class="animation-element"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js"></script>
<script>
window.addEventListener('load', function() {
var animationElement = document.querySelector('.animation-element');
var animation = gsap.to(animationElement, {
x: 100,
duration: 3,
repeat: -1,
yoyo: true
});
animation.pause();
});
</script>
推荐的腾讯云相关产品:无
总结:以上是在页面加载时停止自动启动关键帧动画的几种实现方式,可以根据具体需求选择合适的方法。
领取专属 10元无门槛券
手把手带您无忧上云