当前位置: 首页 > news >正文

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;
  }}

http://www.lryc.cn/news/353262.html

相关文章:

  • yocto学习
  • 【IC设计】牛客网-序列检测习题总结
  • python爬虫登录到海康相机管理页面
  • 9.Docker网络
  • Windows VS2022 C语言使用 sqlite3.dll 访问 SQLite数据库
  • java库和包的概念
  • mysql内存结构
  • Python | Leetcode Python题解之第111题二叉树的最小深度
  • c++二进制输出
  • 5. C++网络编程-UDP协议的实现
  • Altium Designer 中键拖动,滚轮缩放,并修改缩放速度
  • python从入门到精通04
  • tomcat三级指导
  • 不知道是该怎么引用多个函数片段?具体示例如代码
  • P3128 [USACO15DEC] Max Flow P题解(树上差分,最近公共祖先,图论)
  • 在Linux上面部署ELK
  • Langchain-Chatchat的markdownHeaderTextSplitter使用
  • 掩码生成蒸馏——知识蒸馏
  • 【C#实战】Newtonsoft.Json基类子类解析
  • 表达式求值的相关语法知识(C语言)
  • 开发中遇到Electron自定义窗口的问题
  • c# sqlite使用
  • 39、Flink 的窗口剔除器(Evictors)详解
  • Flutter 中的 DefaultTabController 小部件:全面指南
  • C++技能进阶指南——多态语法剖析
  • Linux内存管理--系列文章肆
  • kali下载zsteg和stegpy
  • 前端面试题日常练-day34 【面试题】
  • 网站笔记:huggingface model memory calculator
  • SpringBoot2.0.x旧版集成Swagger UI报错Unable to infer base url...解决办法