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;

}}

相关推荐
yqcoder7 分钟前
闭包是什么?优缺点、怎么防内存泄漏?
前端·http
riuphan12 分钟前
JavaScript 中的 this 关键字
javascript
掰头战士16 分钟前
五分钟带你深入了解 this
javascript
lichenyang45318 分钟前
鸿蒙 ArkUI 组件基础复盘:从两个 UI 卡片回到 ComponentV2、状态管理和组件分层
前端
fantasy_arch21 分钟前
BasicVSR-lite图像画质增强
开发语言·pytorch
biubiubiu_LYQ21 分钟前
萌新小白基础理解篇之 this 关键字
前端·javascript
甜味弥漫22 分钟前
深度解析 JS 中的 this 指向:从底层逻辑到实战规则
javascript·面试
光影少年40 分钟前
Redux 中间件作用(redux-thunk/redux-saga)
前端·react.js·掘金·金石计划
爱上好庆祝42 分钟前
学习JS第十一天(JS的进阶)
前端·javascript·学习
Rust语言中文社区42 分钟前
【Rust日报】2026-05-24 Secluso v1.0.2 版本发布
开发语言·后端·rust