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;

}}

相关推荐
计算机安禾6 分钟前
【数据结构与算法】第28篇:平衡二叉树(AVL树)
开发语言·数据结构·数据库·线性代数·算法·矩阵·visual studio
三万棵雪松11 分钟前
【Linux 物联网网关主控系统-Web部分(一)】
linux·前端·嵌入式linux
csbysj202023 分钟前
网站主机技术概述
开发语言
摸鱼仙人~26 分钟前
增量快照 vs 结构化共享:适用场景全解析
前端·vue.js
froginwe1129 分钟前
jQuery 事件方法详解
开发语言
2301_7717172140 分钟前
Jackson的使用方法详解
java·服务器·前端
A923A1 小时前
【小兔鲜电商前台 | 项目笔记】第八天
前端·vue.js·笔记·项目·小兔鲜
DYuW5gBmH1 小时前
Chrome DevTools MCP 让 AI 无缝接管浏览器调试会话
前端·chrome·chrome devtools
echome8881 小时前
JavaScript Promise 与 async/await 实战:5 个高频异步编程场景的优雅解决方案
开发语言·javascript·ecmascript
xcLeigh2 小时前
IoTDB Java 原生 API 实战:SessionPool 从入门到精通
java·开发语言·数据库·api·iotdb·sessionpool