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;

}}

相关推荐
任子菲阳几秒前
学Java第五十二天——IO流(下)
java·开发语言·intellij-idea
灵犀坠3 分钟前
前端面试&项目实战核心知识点总结(Vue3+Pinia+UniApp+Axios)
前端·javascript·css·面试·职场和发展·uni-app·html
GISer_Jing4 分钟前
SSE Conf大会分享——大模型驱动的智能 可视分析与故事叙述
前端·人工智能·信息可视化
zoujiahui_20185 分钟前
使用venv命令创建和使用python环境
开发语言·python
666HZ6665 分钟前
C语言——putchar 与 getchar
c语言·开发语言
Lovely Ruby5 分钟前
前端er Go-Frame 的学习笔记:实现 to-do 功能(一)
前端·学习·golang
fruge6 分钟前
Vue3 与 Vue2 核心差异:响应式原理、生命周期及迁移方案
前端·javascript·vue.js
zlpzlpzyd11 分钟前
vue.js 3项目整合vue-router 4的问题
前端·javascript·vue.js
crary,记忆12 分钟前
Angular.json中的commonChunk 的作用
前端·javascript·学习·angular.js