- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
阅读关于 CSS animations and how to build them 的文章后,我已经构建了自己的,并且正在尝试提高我的 CSS 动画的性能。我的动画由三个 HTML 元素组成,它们会改变宽度以指示媒体正在播放。
在 Chrome 开发工具中检查时间轴和资源选项卡后,我发现动画导致了高 CPU 负载。
我如何将动画转换为 GPU 硬件加速而不是浏览器渲染器,这会导致高 CPU 负载?我了解到您可以使用硬件加速来强制动画在 GPU 上运行。
有没有办法将此(动画化条形宽度)转换为 GPU 层?我能以某种方式翻译它吗?或者有更好的东西吗?
有 3 个小节。这是它的动画,而不是样式。
@keyframes music {
0% { width:17px; }
10% { width:11px; }
20% { width:37px; }
30% { width:30px; }
40% { width:15px; }
50% { width:10px; }
60% { width:24px; }
70% { width:17px; }
80% { width:21px; }
90% { width:32px; }
100% { width:17px; }
}
.lines-ani {
transform: rotateY(180deg);
}
.lines-ani .lines {
animation: music 1.5s 2s ease-out alternate infinite;
}
.lines-ani .lines:before {
animation: music 1.5s 1.5s ease-out alternate infinite;
}
.lines-ani .lines:after {
animation: music 1.5s 2.5s ease-out alternate infinite;
}
最佳答案
如果您想避免重新绘制并将动画移动到 GPU,那么您可以使用 3D 变换来产生效果,而不是为 width
设置动画。如 this article 中所述,使用 3D 变换意味着浏览器将使动画 GPU 加速。
CSS animations, transforms and transitions are not automatically GPU accelerated, and instead execute from the browser’s slower software rendering engine. So what exactly forces the browser to swap to GPU mode? Many browsers provide GPU acceleration by means of certain CSS rules.
Currently, browsers like Chrome, FireFox, Safari, IE9+ and the latest version of Opera all ship with hardware acceleration; they only use it when they have an indication that a DOM element would benefit from it. With CSS, the strongest indication is that a 3D transformation is being applied to an element.
将动画转换为等效的 3D 变换本身并不是一个大过程。只需要在所有三个元素上设置一个初始的width
,并将@keyframes
规则中的width
转换成它们对应的比率值基于设置的初始宽度。
宽度动画通常只是一个 scaleX
但使用 scale3d
因为我们需要将动画移动到 GPU。由于 scale3d
有 3 个参数(用于三个轴中每个轴的比例),我们可以提供 1(初始比例)作为其他两个轴的值。因此,它将是 scale3d(x ratio, 1, 1)
。
例如,问题中提供的 10%
框架具有 width: 11px
设置,这里是我们如何获得其等效的 scale3d
值:
width
。在下面的代码片段中,我将其设置为 17px。scale3d(0.64, 1, 1)
。 @keyframes color-bar {
0% {
transform: scale3d(1,1,1);
}
10% {
transform: scale3d(0.64,1,1);
}
20% {
transform: scale3d(2.17,1,1);
}
30% {
transform: scale3d(1.76,1,1);
}
40% {
transform: scale3d(0.88,1,1);
}
50% {
transform: scale3d(0.58,1,1);
}
60% {
transform: scale3d(1.41,1,1);
}
70% {
transform: scale3d(1,1,1);
}
80% {
transform: scale3d(1.23,1,1);
}
90% {
transform: scale3d(1.88,1,1);
}
100% {
transform: scale3d(1,1,1);
}
}
.lines-ani {
width: 25vw;
transform: rotateY(180deg);
}
.lines-ani .lines {
position: relative;
width: 17px;
height: 10px;
background: red;
transform-origin: left;
animation: color-bar 1.5s 2s ease-out alternate infinite;
}
.lines-ani .lines:before {
position: absolute;
content: '';
top: 125%;
height: 100%;
width: 100%;
background: green;
transform-origin: left;
animation: color-bar 1.5s 1.5s ease-out alternate infinite;
}
.lines-ani .lines:after {
position: absolute;
content: '';
top: 250%;
height: 100%;
width: 100%;
background: green;
transform-origin: left;
animation: color-bar 1.5s 2.5s ease-out alternate infinite;
}
<div class='lines-ani'>
<div class='lines'>
</div>
</div>
注意:如果您不想使用 scale3d
,您也可以使用 scaleX() translateZ(0)
。 translateZ(0)
是一个 3D 变换,整个过程仍然会产生相同的效果。
关于html - 如何让 CSS 动画使用 GPU(硬件加速)而不是 CPU 渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36512606/
我想在我的 iPhone 应用程序中加入线性回归。经过一些搜索,我发现 Accelerate Framework 中的 LAPACK 和 BLAS 是正确的库。但是我很难将加速框架添加到我的 XCod
有什么方法可以加速 JS 脚本(我指的是一些复杂的 DOM 操作,比如游戏或动画)? 最佳答案 真的没有办法真正加快速度。您可以压缩它,但不会快很多。 关于Javascript 加速?,我们在Stac
有时,我必须为一个项目重新导入数据,从而将大约 360 万行读入 MySQL 表(目前是 InnoDB,但我实际上并不局限于这个引擎)。 “加载数据文件...”已被证明是最快的解决方案,但它有一个权衡
在尝试计算加速时,我被卡住了。所以给出的问题是: 问题 1 如果程序的 50% 增强了 2 倍,其余 50% 增强了 4 倍,那么由于增强而导致的整体加速是多少? Hints:考虑增强前(未增强)机器
目前我正在处理实时绘图,但可视化非常慢。我想知道你可以做些什么来加速 Matplotlib 中的事情: 后端如何影响性能?是否有后端 实时绘图比其他人更好吗? 我可以降低分辨率以提高 FPS 吗? 如
我有一个小型测试框架。它执行一个循环,执行以下操作: 生成一个小的 Haskell 源文件。 使用 runhaskell 执行此操作.该程序生成各种磁盘文件。 处理刚刚生成的磁盘文件。 这种情况发生了
这是我的网站:Instant-YouTube 如您所见,加载需要很长时间。在 IE8 及以下甚至有时会导致浏览器崩溃。我不确定是什么原因造成的。可能是 Clicksor 广告,但我认为是 swfobj
是否可以加速 SKSpriteNode? 我知道可以使用 node.physicsBody.velocity 轻松设置速度但是设置它的加速度有多难? 最佳答案 从牛顿第二定律倒推运动:F = m.a您
有没有人有加速 FCKEditor 的技术?是否有一些关键的 JavaScript 文件可以缩小或删除? 最佳答案 在最新版本 (3.0.1) 中,FCKEditor 已重命名为 CKEditor .
我有以下 MySQL 查询,需要一天多的时间才能执行: SELECT SN,NUMBER FROM a WHERE SN IN (SELECT LOWER_SN FROM b WHER
我现在正在开发一款使用加速来玩的游戏。我找到了如何让我的元素移动,但不改变它的“原点”,或者更准确地说,改变加速度计算的原点: 事实上,我的图像是移动的,它的中心是这样定义的: imageView.c
我有一个 mysql 表,其中存储有 4 列的成员消息: message_id(主键,自增) sender_id( key ) receiver_id( key ) 消息内容 我做了很多 SELECT
我在 cuda_computation.cu 中有以下代码 #include #include #include #include void checkCUDAError(const char
我正在使用 BeautifulSoup 在 for 循环中解析数千个网站。这是我的代码片段: def parse_decision(link): t1 = time.time() de
我正在使用 OpenCV 2.4 (C++) 在灰度图像上进行寻线。这涉及一些基本的图像处理步骤,如模糊、阈值、Canny 边缘检测器、梯度滤波器或霍夫变换。我必须在数千张图像上应用寻线算法。 考虑到
当我试图连续生成四次相同的报告时,我刚刚分析了我的报告应用程序。第一个用了 1859 毫秒,而后面的只用了 400 到 600 毫秒。对此的解释是什么?我能以某种方式使用它来使我的应用程序更快吗?报告
当我打开 Storyboard文件时,由于其中包含的 VC 数量,打开它需要 1-2 分钟。加快速度的最佳做法是什么?我们应该将一些 VC 移动到不同的 Storyboard文件中吗?我们是否应该使用
我有一个包含多个页面的 UIPageViewController。每个页面都是相同的 View Controller ,但会跟踪页码并显示 PDF 的正确页面。问题是每个 PDF 页面都需要在 cur
这实际上是两个问题,但它们非常相似,为了简单起见,我想将它们放在一起: 首先:给定一个已建立的 Java 项目,除了简单的代码内优化之外,还有哪些不错的方法可以加快它的速度? 其次:在用Java从头写
我有一个包含 1000 个条目的文档,其格式类似于:
我是一名优秀的程序员,十分优秀!