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_陈寒14 小时前
React的useEffect依赖数组把我坑惨了,真相其实很简单
前端·人工智能·后端
徐小夕14 小时前
JitWord 3.0 正式发布,高精度Word异构解析+复杂组件兼容,打造web端协同Word编辑器
前端·vue.js·算法
恋猫de小郭14 小时前
KMP / CMP 鸿蒙版本 Beta 发布,他有什么特别之处?
android·前端·flutter
乘风gg15 小时前
OpenClaw 爆火,但”飞书"赢麻了!!!
前端·ai编程·claude
Oneslide15 小时前
React 纯前端技术栈报告(2026年)
前端
前端一小卒15 小时前
AI 时代,前端工程化要重做一遍
前端
橙子家1 天前
浏览器缓存之【基础键值存储】:Local storage 和 Session storage
前端
星星在线1 天前
MusicFree:一个「All in One」的个人音乐服务器,让听歌回归简单
前端·后端
IT_陈寒1 天前
Redis的SETNX并发问题让我加了三天班
前端·人工智能·后端
demo007x1 天前
Docling 文档转换以及技术架构分析
前端·后端·程序员