js实现元素根据鼠标滚轮滚动向左右上下滑动着从模糊到清楚显示出来

html代码

<div ref={test} id="animatedElement" className="not-animated">

<div style={{width:"100px",height:"50px",backgroundColor:"red"}}>

</div>

</div>

JS代码

const test = useRef(null)

// 监听滚轮事件

useEffect(() => {

const handleScrollaa = () => {

const scrollTop1 = document.documentElement.scrollTop || document.body.scrollTop;

const h = test.current;

const triggerPoint = window.innerHeight

if (scrollTop1 > triggerPoint * 0.3) {

// 触发动画,通过添加 animate 类

console.log(32135456434687)

(headerLogo2 as HTMLElement).style.animation = `ROW3 2s forwards`;

}

else if(scrollTop1 < triggerPoint * 0.3){

h.style.animation=""

h.style.opacity="0"

}

};

window.addEventListener('scroll', handleScrollaa);

// 组件卸载时移除事件监听器

return () => {

window.removeEventListener('scroll', handleScrollaa);

};

}, []);

CSS代码(实现从左到右滑动出来,并且由模糊到清楚的展现)

@keyframes ROW3 {

0% {

transform: translateX(-100%); /* 动画开始时,图片在容器外部 */

filter: blur(30px); /*模糊属性*/

opacity:0; /*opacity: 0 隐藏 1 显示 */

}

100% {

transform: translateX(0) rotate(1turn) ; /* 动画结束时,图片移动到容器内部 rotate(1turn)是内容旋转,随着移动而滚动 */

filter: blur(0);

opacity:1;

}}

相关推荐
ZC跨境爬虫7 分钟前
Scrapy实战爬取5sing网站:Pipeline优化+全流程踩坑复盘,从报错到数据落地
前端·爬虫·python·scrapy
牛马11117 分钟前
Flutter BoxDecoration
前端·javascript·flutter
xianluohuanxiang22 分钟前
高精度气象:极端天气一来,零售最先出问题的不是客流,而是补货体系和损失控制
开发语言·人工智能·深度学习·机器学习·零售
KKKlucifer23 分钟前
零信任融合 4A 平台,构建全域身份动态可信管控体系
开发语言·php
M ? A35 分钟前
VuReact 编译器核心重构:统一管理组件元数据收集
前端·javascript·vue.js·react.js·重构·开源
山海AI手册37 分钟前
030、AI应用前端展示:Streamlit快速构建交互式Web应用
前端·人工智能
专注VB编程开发20年38 分钟前
C#异步状态机,内部的信号机制TaskCompletionSource
前端
csdn_aspnet41 分钟前
在无状态 ASP.NET Core 8 Web API 中实现 CSRF 令牌,无需 Views/MVC!
前端·csrf·.net core
txzrxz42 分钟前
c++深度搜索讲解及例题
开发语言·c++·深度搜索·例题讲解
yu859395842 分钟前
时延估计的互相关算法(MATLAB实现)
开发语言·算法·matlab