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;

}}

相关推荐
Jx6577 小时前
初学者视角下的JavaScript作用域理解
javascript
lly2024067 小时前
《jEasyUI 取得选中行数据》
开发语言
AlbertZein7 小时前
干了三年全栈才悟到:TS + React 这套组合,真不是堆技术堆出来的
前端
化为五月7 小时前
我把 Hermes 接进了飞书,结果卡在“能发消息但就是不回”
前端
ClouGence7 小时前
豆包收费之后,我找到了更好用的 AI 工具
前端·人工智能·后端·ai·ai编程·ai写作
aircrushin7 小时前
音乐节结束前,拿手机📱搓了一个工具
前端·后端
廖松洋(Alina)7 小时前
07答案比对与反馈UI-鸿蒙PC端Electron开发
javascript·ui·华为·electron·开源·harmonyos·鸿蒙
风骏时光牛马8 小时前
Cube Sandbox部署问题及解决方法
前端
Bug-制造者8 小时前
深入理解 HTML5 Web Workers:提升网页性能的关键技术解析
前端·html·html5
Ulyanov8 小时前
《从质点到位姿:基于Python与PyVista的导弹制导控制全栈仿真》: 刚体觉醒——6-DOF刚体动力学、四元数与全姿态解算
开发语言·人工智能·python·算法·系统仿真·雷达电子对抗仿真