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;

}}

相关推荐
不要额外加糖几秒前
给 Codex 戴上紧箍, 治一治 AI 的过度发挥
前端·人工智能·代码规范
basketball6163 分钟前
设计模式入门:2. 工厂模式详解 C++实现
开发语言·c++·设计模式
Lumbrologist3 分钟前
【C++】零基础入门 · 第 16 节:智能指针
开发语言·c++
yu85939584 分钟前
MATLAB 分支定界法(Branch and Bound)实现
开发语言·matlab
学会去珍惜10 分钟前
c语言编程 C语言入门 c语言(C语言程序设计教程 c语言视频教程 c语言零基础
c语言·开发语言
吃阿茶搽20 分钟前
源码剖析:Standard组件架构与底层实现原理
javascript
文心快码BaiduComate22 分钟前
Comate搭载MiniMax M3:支持超长百万上下文
前端·人工智能·后端
浩风祭月22 分钟前
React 18 并发特性实战:用 useTransition 和 useDeferredValue 优化列表搜索体验
前端·react native
WebInfra23 分钟前
TanStack Start 框架正式支持 Rsbuild
前端·javascript·前端框架