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;

}}

相关推荐
济南壹软网络科技有限公司18 小时前
沉浸式体验革命:壹软科技2025新版盲盒源码前端3D渲染与个性化运营技术解析
前端·科技·uni-app·开源·php·盲盒源码
陈随易18 小时前
MoonBit语法基础概述
前端·后端·程序员
v***431718 小时前
springboot3整合knife4j详细版,包会!(不带swagger2玩)
android·前端·后端
似水এ᭄往昔19 小时前
【C++】--二叉搜索树
开发语言·数据结构·c++
parade岁月19 小时前
理解 CSS backface-visibility:卡片翻转效果背后的属性
前端·css
用户479492835691519 小时前
为什么 react-grab 可以在 Vue 项目中使用?
前端·ai编程
大道戏19 小时前
互联网程序设计第12 讲 RMI 程序设计
java·开发语言·计算机网络
水木姚姚19 小时前
C++程序创建(VS Code)
开发语言·c++
666HZ66619 小时前
C语言——C++的引用
c语言·开发语言·c++
San30.19 小时前
深入 JavaScript 原型与面向对象:从对象字面量到类语法糖
开发语言·javascript·ecmascript