13个AE常用表达式:文本篇
深圳/UI设计师/342天前/350浏览
版权
13个AE常用表达式:文本篇
从简单到可高度自定义的表达式,分的比较细,大家按需自取。如果不够简洁,欢迎大家分享指正、一起进步。
以下不是实现动画的唯一标准~
——
01 数值递增(无上限)
(time*100).toFixed(0)+"%"
02 数值递增&递减(设置上限)
linear(time,0,2,1,100).toFixed(1)+"%"
解析:0-2秒之内完成1-100的变化;其他与上面的一样,也可设置小数点位数以及单位。
03 数值递增&递减(单位在前)
value = linear(time,0,2,1,100).toFixed(1);"¥" + value
解析:同上。只是套了个“value”表示数字。如果是【value+“¥”】单位依旧会在后。
04 时间(简单)
timeToCurrentFormat(time)
05 时间(自定义起始时间)
// 自定义起始时间(格式:小时、分钟、秒、毫秒)startHours = 0; // 小时startMinutes = 20; // 分钟startSeconds = 0; // 秒startMilliseconds = 0; // 毫秒startOffset = startHours * 3600 + startMinutes * 60 + startSeconds + startMilliseconds / 100;elapsedTime = time + startOffset;hours = Math.floor(elapsedTime / 3600);minutes = Math.floor((elapsedTime % 3600) / 60);seconds = Math.floor(elapsedTime % 60);milliseconds = Math.floor((elapsedTime % 1) * 100);function padZero(num) {return ("0" + num).slice(-2);}padZero(hours) + ":" + padZero(minutes) + ":" + padZero(seconds) + ":" + padZero(milliseconds);
解析:前4行可分别设置 时:分:秒:毫秒,我设置的是00:20:00:00分开始。其他的直接一起复制粘贴就好。
06 时间(自定义起始时间+格式)
// 自定义起始时间(格式:小时、分钟、秒、毫秒)
startHours = 0; // 小时startMinutes = 20; // 分钟startSeconds = 0; // 秒startMilliseconds = 0; // 毫秒startTime = startHours * 3600 + startMinutes * 60 + startSeconds + startMilliseconds / 100;elapsedTime = time + startTime;hours = Math.floor(elapsedTime / 3600);minutes = Math.floor((elapsedTime % 3600) / 60);seconds = Math.floor(elapsedTime % 60);milliseconds = Math.floor((elapsedTime % 1) * 100);function padZero(num) { return ("0" + num).slice(-2); }// 自定义格式format = "hh:mm:ss:SS"; // 修改此变量以切换格式output = format.replace("hh", padZero(hours)).replace("mm", padZero(minutes)).replace("ss", padZero(seconds)).replace("SS", padZero(milliseconds));output;
解析:后面增加了时间格式。下面我去掉了“小时”。
07 时间(倒数)
// 自定义起始时间(格式:小时、分钟、秒、毫秒)startHours = 0; // 小时startMinutes = 20; // 分钟startSeconds = 0; // 秒startMilliseconds = 0; // 毫秒startTime = startHours * 3600 + startMinutes * 60 + startSeconds + startMilliseconds / 100;remainingTime = Math.max(0, startTime - time);hours = Math.floor(remainingTime / 3600);minutes = Math.floor((remainingTime % 3600) / 60);seconds = Math.floor(remainingTime % 60);milliseconds = Math.floor((remainingTime % 1) * 100);function padZero(num) { return ("0" + num).slice(-2); }// 自定义格式format = "hh:mm:ss:SS"; // 修改此变量以切换格式output = format.replace("hh", padZero(hours)).replace("mm", padZero(minutes)).replace("ss", padZero(seconds)).replace("SS", padZero(milliseconds));output;
08 打字效果
textContent = "Hello, After Effects!"; // 文本内容chars = textContent.length;speed = 14; // 每秒显示字符数visibleChars = Math.min(chars, Math.floor(time * speed));textContent.substr(0, visibleChars)
通过 文本动画 》不透明度 打关键帧也可实现。
09 随机选择(内幕🤔)
data = ["广州", "青岛", "三亚", "杭州", "北京", "长沙", "新疆"]; // 自定义内容stopText = "三亚"; // 停止时显示stopTime = 2; // 停止时间(秒)if (time >= stopTime) {output = stopText;} else {output = data[Math.floor(random(data.length))];}output;
10 数字乱码
rows = 5; // 行数cols = 5; // 列数startValue = 100; // 基础数字speed = 10; // 数字变化速度randomFactor = 50; // 随机因子范围s = "";for (i = 0; i < rows; i++) {for (j = 0; j < cols; j++) {num = Math.round(startValue +time * speed +i * j * 3 +random(-randomFactor, randomFactor));s += num + " ";}s += "\n";}s;
11 乱码 》逐字显示最终文字
textContent = "A Password"; // 目标文本randomChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; //随机文本speed = 10; // 每秒显示字符数chars = textContent.length;visibleChars = Math.min(chars, Math.floor(time * speed));result = "";for (i = 0; i < chars; i++) {if (i < visibleChars) {result += textContent[i];} else {result += randomChar[Math.floor(random(randomChar.length))]; // 显示随机字符}}result
12 字幕切换(固定时间)
story = ["从前有座山","山里有座庙","庙里有个老和尚和个小和尚","老和尚对小和尚说",];sentenceDuration = 1; // 每句的持续时间currentSentence = Math.floor(time / sentenceDuration) % story.length;story[currentSentence]
13 歌词切换(指定时间)
lyrics = [{ time: 0, text: "下雨天了怎么办" },{ time: 3, text: "我好想你" },{ time: 6, text: "不敢打给你" },{ time: 9, text: "我找不到原因" }];currentLyric = "";for (i = 0; i < lyrics.length; i++) {if (time >= lyrics[i].time) {currentLyric = lyrics[i].text;}}currentLyric
——
发现好玩的会继续更新..
7
Report
声明
20
Share
相关推荐
in to comment
Add emoji
喜欢TA的作品吗?喜欢就快来夸夸TA吧!
You may like
相关收藏夹
Log in
7Log in and synchronize recommended records
20Log in and add to My Favorites
评论Log in and comment your thoughts
分享Share










































![AIGC助力电商视觉×头盔系列AI生成 [动态化探索实践]](https://img.zcool.cn/community/68e8da720067cv09d9quve1777.png?x-oss-process=image/resize,m_fill,w_520,h_390,limit_1/auto-orient,1/sharpen,100/quality,q_80)

































