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;

}}

相关推荐
Mr_Xuhhh7 分钟前
从理论到实践:深入理解算法的时间与空间复杂度
java·开发语言·算法
Lenyiin14 分钟前
《Python 修炼全景指南:一》从环境搭建到第一个程序
开发语言·python
码事漫谈28 分钟前
AI提效,到底能强到什么程度?
前端·后端
IT_陈寒29 分钟前
React hooks依赖数组这个坑差点把我埋了
前端·人工智能·后端
涛声依旧3931634 分钟前
Python项目实战:学生信息管理系统
开发语言·python·数据挖掘
阿祖zu1 小时前
内容创作 AI 透明化声明倡议与项目开源
前端·后端·github
企鹅的蚂蚁1 小时前
【ESP32-S3开发踩坑】C++野指针引发的LoadProhibited死机与CMake依赖锁死排查
开发语言·c++
XiaoQiao6669991 小时前
python 简单题目练手【详解版】【1】
开发语言·python
lpfasd1231 小时前
TypeScript + Cloudflare 全家桶部署项目全流程
前端·javascript·typescript
Kiling_07041 小时前
Java多态、final与抽象类:面向对象编程进阶指南
java·开发语言