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;

}}

相关推荐
≮傷£≯√3 小时前
QT配置FFmpeg
开发语言·qt·ffmpeg
三8443 小时前
RCE长度&字符限制绕过
开发语言·php
weixin_469273813 小时前
.md文件是什么?.md如何打开?
前端·编辑器
不好听6133 小时前
Web Worker:浏览器给 JS 开的后台子线程
前端·浏览器
用户24171401418604 小时前
一个 Tapas 菜单 App,逼我啃下了前端存储和 this 绑定两座大山
javascript
计算机魔术师4 小时前
数据分析还在靠人跑 SQL?AI 智能体已经把效率拉到 63 倍
前端
小陈的进阶之路4 小时前
爬虫三大解析库:lxml, jsonpath, bs4
开发语言·笔记·python
wuyk5554 小时前
第1章:无刷电机核心原理与运行机制
c语言·开发语言·stm32·单片机·嵌入式硬件·机器学习
瑞码空间4 小时前
Routing & API:前后端协作的本质与实现
前端·后端·接口·路由
SomeB1oody4 小时前
【RustyML入门】2.10. 主成分分析
开发语言·后端·机器学习·rust·教程