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;

}}

相关推荐
IT_陈寒2 小时前
React的这个渲染问题连官方文档都没说清楚
前端·人工智能·后端
追逐时光者3 小时前
别再满网找零散工具了,腾讯 QQ 浏览器这个“帮小忙”工具箱真能省时间
前端·后端
To_OC5 小时前
LC 200 岛屿数量:经典 DFS 入门题,我第一次写居然连方向都搞错了
javascript·算法·leetcode
Asmewill5 小时前
grep&curl命令学习笔记
前端
stringwu5 小时前
Flutter 开发必备:MVI 架构的高效实现指南
前端·flutter
用户2136610035726 小时前
Vue2组件化开发与父子通信
前端·vue.js
Momo__7 小时前
TypeScript satisfies 操作符——比 as 更安全的类型守门员
前端·typescript
用户2136610035727 小时前
Vue2事件系统与指令进阶
前端·vue.js
labixiong7 小时前
实现一个能跑的迷你版Promise(一)
前端·javascript·面试
Csvn9 小时前
`??` 和 `||` 搞混,线上用户头像全挂了
前端