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;

}}

相关推荐
CC码码6 分钟前
告别杂乱数字:用 Intl.NumberFormat 打造全球友好的前端体验
前端·javascript·面试
Tony Bai7 分钟前
Goroutine “气泡”宇宙——Go 并发模型的新维度
开发语言·后端·golang
kandee15 分钟前
vscode混淆js文件的插件用法(jshaman)
javascript·ide·vscode
妮妮喔妮15 分钟前
Webpack和Vite优化的区别
前端·webpack·node.js
Larry_Yanan17 分钟前
Qt多进程(二)QProcess+stdio
开发语言·qt
码农葫芦侠19 分钟前
Qt 跨线程内存管理陷阱:QSharedPointer、deleteLater() 与 QPointer 的致命组合
开发语言·数据库·qt
d111111111d22 分钟前
C语言中,malloc和free是什么,在STM32中使用限制是什么,该如何使用?
c语言·开发语言·笔记·stm32·单片机·嵌入式硬件·学习
网安_秋刀鱼25 分钟前
【java安全】shiro鉴权绕过
java·开发语言·安全
白昼流星!33 分钟前
C++内存四区与new操作符详解
开发语言·c++
tyatyatya33 分钟前
MATLAB三维绘图教程:plot3/mesh/surf/contour函数详解与实例
开发语言·matlab