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;

}}

相关推荐
星火开发设计33 分钟前
模板参数:类型参数与非类型参数的区别
java·开发语言·前端·数据库·c++·算法
忘梓.43 分钟前
二叉搜索树·极速分拣篇」:用C++怒肝《双截棍》分拣算法,暴打节点删除Boss战!
开发语言·c++·算法
星辰徐哥44 分钟前
Java数组的定义、操作与应用场景
java·开发语言
Aileen_0v01 小时前
【数据结构中链表常用的方法实现过程】
java·开发语言·数据结构·算法·链表·动态规划·csdn开发云
草莓熊Lotso1 小时前
《算法闯关指南:优选算法--滑动窗口》--15.串联所有单词的子串,16.最小覆盖子串
开发语言·c++·人工智能·算法
Andy Dennis1 小时前
一文认识Java常见集合
java·开发语言
kyle~2 小时前
Python---Flask 轻量级Web框架
开发语言·python·flask
云深处@2 小时前
【C++11】特殊类&&单例模式
开发语言·c++
烟花落o3 小时前
算法的时间复杂度和空间复杂度
开发语言·数据结构·笔记·算法
cc.ChenLy3 小时前
【CSS进阶】毛玻璃效果与代码解析
前端·javascript·css