will-change
目的:
让GPU分担CPU的工作,从而优化和分配内存,告知浏览器做好动画的准备。
背景:

注意事项:
1,will-change虽然可以加速,但是,一定一定要适度使用;
2,使用伪元素,独立渲染:
不要这样直接写在默认状态中,因为will-change会一直挂着:
.a {
will-change: transform;
transition: transform 0.3s;
}
.a:hover {
transform: scale(1.5);
}
解决方案:
可以让父元素hover的时候,声明will-change,这样,移出的时候就会自动remove,触发的范围基本上是有效元素范围。
.a-parent:hover .a {
will-change: transform;
}
.a {
transition: transform 0.3s;
}
.a:hover {
transform: scale(1.5);
}
3,如果使用JS添加will-change, 事件或动画完毕,一定要及时remove. 比方说点击某个按钮,其他某个元素进行动画。点击按钮(click),要先按下(mousedown)再抬起才出发。因此,可以mousedown时候打声招呼, 动画结束自带回调,于是:
dom.onmousedown = function() {
target.style.willChange = 'transform';
};
dom.onclick = function() {
// target动画哔哩哔哩...
};
target.onanimationend = function() {
// 动画结束回调,移除will-change
this.style.willChange = 'auto';
};
官方:https://developer.mozilla.org/en/docs/Web/CSS/will-change ,给出的示例:
var el = document.getElementById('element');
// Set will-change when the element is hovered
el.addEventListener('mouseenter', hintBrowser);
el.addEventListener('animationEnd', removeHint);
function hintBrowser() {
// The optimizable properties that are going to change
// in the animation's keyframes block
this.style.willChange = 'transform, opacity';
}
function removeHint() {
this.style.willChange = 'auto';
}
will-change的更多相关文章
- 代码的坏味道(10)——发散式变化(Divergent Change)
坏味道--发散式变化(Divergent Change) 发散式变化(Divergent Change) 类似于 霰弹式修改(Shotgun Surgery) ,但实际上完全不同.发散式变化(Dive ...
- [LeetCode] Coin Change 硬币找零
You are given coins of different denominations and a total amount of money amount. Write a function ...
- input事件与change事件
输入框的change事件: 必须等到输入框失去焦点的时候才会触发,鼠标在空白的地方点一下: 输入框的input事件: 在输入内容变化的同时,实时的触发,不需要等到失去焦点.
- Change the Target Recovery Time of a Database (SQL Server) 间接-checkpoints flushcache flushcache-message
Change the Target Recovery Time of a Database (SQL Server) 间接checkpoints flushcache flushcache-mes ...
- Change Line Type in OpenCascade
Change Line Type in OpenCascade eryar@163.com 关键字KeyWords:OpenCascade,Line Aspect, Line Type 在OpenCa ...
- 华硕笔记本U盘启动系统/WinPE报错。Windows failed to start. A Recent hardware or software change might be the cause.
最近在整一台华硕笔记本,大概有5年寿命了吧,质量还行,由于系统出了问题,打算用自制U盘WinPE进去修复一下.按照个人经验,在主板设置里启用了USB启动选项,并且设置USB启动顺序为第一个,可是进系统 ...
- You cannot change a partition into an extended one or vice versa Delete it first
在Linux扩展LVM时,使用fdisk创建分区时,在磁盘上新建扩展分区(逻辑分区),修改分区格式,指定分区类型为8e时,报错"You cannot change a partition i ...
- [WPF系列]基础 Listening to Dependency Property change notifications of a given Element
I want to share this great post from Anoop that shows a easy way to add a notification system to dep ...
- 鼠标的change事件
原本想着在<input>输入输入框中添加change事件,来实现对输入内容的限定. 当人们在使用时跟多的会直接去点击完成.所以完成按钮的点击事件会和change事件产生 冲突,所以我把验证 ...
- Fold Change和t分布
基因表达谱数据 基因表达谱可以用一个矩阵来表示,每一行代表一个基因,每一列代表一个样本(如图1).所有基因的表达谱数据在“gene_exp.txt”文件中存储,第一列为基因的entrez geneid ...
随机推荐
- sql中一列拆成两列
declare @table table (name nvarchar(4))insert into @tableselect '张三' union allselect '李四' union alls ...
- HttpOperater-模拟HTTP操作类
using System; using System.IO; using System.Linq; using System.Net; using System.Text; using System. ...
- jquery操作复选框(checkbox)十二技巧
jquery操作复选框(checkbox)的12个小技巧. 1.获取单个checkbox选中项(三种写法)$("input:checkbox:checked").val()或者$( ...
- Atitit.注册跟个登录功能的实现attilax总结obo
Atitit.注册跟个登录功能的实现attilax总结obo 1. 注册模块 2 1.1. 基本注册功能(用户名方式) 2 1.2. 动态ajax监测用户名重复 2 1.3. 注册手机验证 2 1.4 ...
- 线程相关函数(7)-sem_post(), sem_wait() 信号量
sem_tsem_initsem_waitsem_trywaitsem_timedwaitsem_postsem_destroy 生产者消费者实例: #include <stdlib.h> ...
- 在ajax请求体外得到请求 数据
function sendAjax() { $.ajax({ type: "post", url: "/flow/process/trace.afca?pid=" ...
- Python 元祖的操作
注意:元祖定义后不可修改,单个元祖后面必须加逗号,否则认为是字符串:tuple = ('apple',) 1.定义元祖 tuple = ('apple','banana','grape','orang ...
- Android中<uses-sdk>属性和target属性分析
1. 概要 <uses-sdk> 用来描述该应用程序可以运行的最小和最大API级别,以及应用程序开发者设计期望运行的平台版本.通过在manifest清单文件中添加该属性,我们可以更好的控制 ...
- hdu1078(记忆化搜索)
题意:给出n*n的格子,每个各自里面有些食物,问一只老鼠每次走最多k步所能吃到的最多的食物 这道题目,值得我记住它,re了n次,以前写搜索没有注意的一个小地方,导致re这么多次的 ac代码: #inc ...
- Linux动态库开发
http://blog.csdn.net/qq_33850438/article/details/52014399 ### 导出符号------------------------------ 默认所 ...