前端动画:别再用 jQuery animate 了

前端动画:别再用 jQuery animate 了

毒舌时刻

这动画效果做得跟幻灯片似的,一点都不流畅。

各位前端同行,咱们今天聊聊前端动画。别告诉我你还在使用 jQuery animate,那感觉就像在没有减震器的情况下开车——能开,但颠簸得要命。

为什么你需要现代前端动画

最近看到一个项目,动画效果卡顿,代码复杂难以维护。我就想问:你是在做动画还是在做卡顿展示?

反面教材

// 反面教材:使用 jQuery animate // index.html <!DOCTYPE html> <html> <head> <title>jQuery Animation</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style> .box { width: 100px; height: 100px; background-color: red; position: relative; } </style> </head> <body> <div></div> <button>动画</button> <script src="app.js"></script> </body> </html> // app.js $(document).ready(function() { $('#animate').click(function() { $('.box').animate({ left: '200px', opacity: '0.5', height: '200px', width: '200px' }, 1000); }); }); 

毒舌点评:这动画,就像在看幻灯片,一点都不流畅。

正确姿势

1. CSS 动画

/* 正确姿势:CSS 动画 */ /* styles.css */ .box { width: 100px; height: 100px; background-color: red; position: relative; transition: all 0.3s ease; } .box:hover { transform: scale(1.2); background-color: blue; } .box.animate { animation: move 1s ease forwards; } @keyframes move { from { left: 0; opacity: 1; height: 100px; width: 100px; } to { left: 200px; opacity: 0.5; height: 200px; width: 200px; } } /* index.html */ <!DOCTYPE html> <html> <head> <title>CSS Animation</title> <link rel="stylesheet" href="styles.css"> </head> <body> <div></div> <button>动画</button> <script src="app.js"></script> </body> </html> /* app.js */ document.getElementById('animate').addEventListener('click', function() { const box = document.querySelector('.box'); box.classList.add('animate'); setTimeout(() => { box.classList.remove('animate'); }, 1000); }); 

2. Framer Motion

// 正确姿势:Framer Motion // 1. 安装依赖 // npm install framer-motion // 2. 基本使用 import React, { useState } from 'react'; import { motion } from 'framer-motion'; function App() { const [animate, setAnimate] = useState(false); return ( <div> <motion.div className="box" initial={{ x: 0, opacity: 1, height: 100, width: 100 }} animate={animate ? { x: 200, opacity: 0.5, height: 200, width: 200 } : {}} transition={{ duration: 1 }} whileHover={{ scale: 1.1, backgroundColor: 'blue' }} /> <button onClick={() => setAnimate(!animate)}> {animate ? '重置' : '动画'} </button> </div> ); } export default App; // styles.css .box { background-color: red; position: relative; } 

3. GreenSock Animation Platform (GSAP)

// 正确姿势:GSAP // 1. 安装依赖 // npm install gsap // 2. 基本使用 import React, { useRef, useEffect } from 'react'; import gsap from 'gsap'; function App() { const boxRef = useRef(null); const handleAnimate = () => { gsap.to(boxRef.current, { x: 200, opacity: 0.5, height: 200, width: 200, duration: 1, ease: 'power2.out' }); }; const handleReset = () => { gsap.to(boxRef.current, { x: 0, opacity: 1, height: 100, width: 100, duration: 1, ease: 'power2.out' }); }; return ( <div> <div ref={boxRef} className="box"></div> <button onClick={handleAnimate}>动画</button> <button onClick={handleReset}>重置</button> </div> ); } export default App; // styles.css .box { width: 100px; height: 100px; background-color: red; position: relative; } 

4. React Spring

// 正确姿势:React Spring // 1. 安装依赖 // npm install @react-spring/web // 2. 基本使用 import React, { useState } from 'react'; import { useSpring, animated } from '@react-spring/web'; function App() { const [animate, setAnimate] = useState(false); const styles = useSpring({ x: animate ? 200 : 0, opacity: animate ? 0.5 : 1, height: animate ? 200 : 100, width: animate ? 200 : 100, config: { duration: 1000 } }); return ( <div> <animated.div className="box" style={styles} /> <button onClick={() => setAnimate(!animate)}> {animate ? '重置' : '动画'} </button> </div> ); } export default App; // styles.css .box { background-color: red; position: relative; } 

毒舌点评:这才叫现代前端动画,流畅自然,代码简洁,再也不用担心动画卡顿和维护困难了。

Read more

基于西门子S7-1200FC PLC与松下机器人Profinet通信实现机器人外部自动控制应用

⒈训练主题 通过西门子S7-1200 PLC与松下机器人Profinet通信实现机器人的外部自动化控制,应用中程序的调配采用二进制方式,同时PLC需要采集机器人安全作业原点(Home点),保证机器人安全作业,通过PLC的编程调试和机器人的配置实现上述功能。 ⒉软硬件配置 ⑴硬件配置 ①机器人控制系统:TM1800G3机器人:YA-1VAR81;机器人连接电缆:TSMWU894LM;电缆单元:TSMWU600;200V/380V变压器:TSMTR010HGG;RT轴焊丝盘架(刚用):TSMYU204;校枪尺:AXU01727T;机器人通信装置(Profinet):TSMYU965,产品实物如下图。 ②西门子PLC:CPU 1214FC DC/DC/RLY,型号:6ES7 214-1HF40-0XB0。 ③按钮:若干。 ④调试电脑1台,注意电脑IP地址在同一个网段(IP:192.168.0.***),子网掩码为:255.255.255.

ComfyUI Manager:AI绘画工作流的智能指挥中心

ComfyUI Manager:AI绘画工作流的智能指挥中心 【免费下载链接】ComfyUI-Manager 项目地址: https://gitcode.com/gh_mirrors/co/ComfyUI-Manager 在数字艺术创作的海洋中,ComfyUI Manager犹如一艘精密的指挥舰,为AI绘画爱好者们提供全方位的插件与模型管理解决方案。这个强大的工具不仅简化了工作流程,更让创意表达变得更加自由流畅。 快速上手:构建你的数字画室 开始使用ComfyUI Manager的第一步是将其部署到你的工作环境中。通过以下命令,你可以轻松获取这个强大的管理工具: cd custom_nodes && git clone https://gitcode.com/gh_mirrors/co/ComfyUI-Manager comfyui-manager 部署完成后,重启ComfyUI应用程序,你将在界面中发现全新的"Manager"入口,这正是通往高效创作世界的大门。 核心功能深度解析 插件生态系统的智能调度

Nunchaku FLUX.1 CustomV3:让AI绘画变得简单又高效

Nunchaku FLUX.1 CustomV3:让AI绘画变得简单又高效 你是不是也遇到过这些情况: 想用AI画一张海报,结果调了半小时参数,生成的图不是手多一只,就是背景糊成一团; 下载了一个新模型,光是装依赖、配环境就折腾一整天,最后连界面都没打开; 看到别人发的精美插画心痒痒,可翻遍教程还是搞不清“CLIP”“LoRA”“CFG scale”到底在哪儿改、怎么调…… 别急——这次不用折腾。Nunchaku FLUX.1 CustomV3 镜像,就是为“不想研究原理,只想马上出图”的你准备的。 它不是又一个需要手动拼接节点、反复调试权重的复杂工作流,而是一套开箱即用、单卡RTX4090就能跑、改两行文字就能出高质量图的文生图方案。背后融合了 FLUX.1-dev 的强生成能力、FLUX.1-Turbo-Alpha 的响应速度,以及 Ghibsky Illustration LoRA 的细腻画风加持—

AI绘画创业第一步:Stable Diffusion 3.5低成本验证方案

AI绘画创业第一步:Stable Diffusion 3.5低成本验证方案 你是不是也经常刷到别人用AI画出精美插画、定制头像、甚至接单赚钱?看着心动,但又怕买设备、学软件、投钱打水漂?别担心,作为一个从零开始摸索过来的自由职业者,我完全理解你的顾虑。 今天我要分享的,是一套专为自由职业者设计的AI绘画副业启动方案——利用 Stable Diffusion 3.5(SD 3.5) 和云端GPU资源,实现“零硬件投入、低时间成本、快速出图变现”的可行性验证路径。整个过程不需要你懂编程,也不用买显卡,只要会打字、会上网,就能在几个小时内跑通全流程。 为什么选 SD 3.5?因为它不仅是目前开源图像生成模型中的“顶流”,还特别适合商业应用:支持更高分辨率、细节更精细、文字渲染能力更强,而且对提示词(prompt)的理解更加自然。更重要的是,