css animation 触发,在JavaScript中触发CSS动画

本文介绍了一种不依赖JQuery的动画触发方式,利用纯JavaScript侦测用户滚动页面的行为,并手动启动预定义的CSS动画效果。该方法适用于希望减少外部依赖的项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我不知道如何使用JQuery,因此我需要一种仅可以使用JavaScript触发动画的方法。

当用户滚动页面时,我需要调用/触发CSS动画。

function start() {

document.getElementById('logo').style.animation = "anim 2s 2s forward";

document.getElementById('earthlogo').style.animation = "anim2 2s 2s forward";

}

* {

margin: 0px;

}

#logo {

position: fixed;

top: 200px;

height: 200px;

width: 1000px;

left: 5%;

z-index: 4;

opacity: 0.8;

}

#earthlogo {

position: fixed;

top: 200px;

height: 120px;

align-self: center;

left: 5%;

margin-left: 870px;

margin-top: 60px;

z-index: 4;

opacity: 0.9;

}

@keyframes anim {

50% {

filter: blur(10px);

transform: rotate(-15deg);

box-shadow: 0px 0px 10px 3px;

}

100% {

height: 100px;

width: 500px;

left: 10px;

top: 10px;

box-shadow: 0px 0px 15px 5px rgba(0, 0, 0, 0.7);

background-color: rgba(0, 0, 1, 0.3);

opacity: 0.7;

}

}

@keyframes anim2 {

50% {

filter: blur(40px);

transform: rotate(-15deg);

}

100% {

height: 60px;

width: 60px;

left: 10px;

top: 10px;

margin-left: 435px;

margin-top: 30px;

opacity: 0.8;

}

}

#backstar {

position: fixed;

width: 100%;

z-index: 1;

}

#earth {

position: absolute;

width: 100%;

z-index: 2;

top: 300px;

}

earth.png

stars.jpg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值