目的:

 让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的更多相关文章

  1. 代码的坏味道(10)——发散式变化(Divergent Change)

    坏味道--发散式变化(Divergent Change) 发散式变化(Divergent Change) 类似于 霰弹式修改(Shotgun Surgery) ,但实际上完全不同.发散式变化(Dive ...

  2. [LeetCode] Coin Change 硬币找零

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  3. input事件与change事件

    输入框的change事件: 必须等到输入框失去焦点的时候才会触发,鼠标在空白的地方点一下: 输入框的input事件: 在输入内容变化的同时,实时的触发,不需要等到失去焦点.

  4. 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 ...

  5. Change Line Type in OpenCascade

    Change Line Type in OpenCascade eryar@163.com 关键字KeyWords:OpenCascade,Line Aspect, Line Type 在OpenCa ...

  6. 华硕笔记本U盘启动系统/WinPE报错。Windows failed to start. A Recent hardware or software change might be the cause.

    最近在整一台华硕笔记本,大概有5年寿命了吧,质量还行,由于系统出了问题,打算用自制U盘WinPE进去修复一下.按照个人经验,在主板设置里启用了USB启动选项,并且设置USB启动顺序为第一个,可是进系统 ...

  7. 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 ...

  8. [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 ...

  9. 鼠标的change事件

    原本想着在<input>输入输入框中添加change事件,来实现对输入内容的限定. 当人们在使用时跟多的会直接去点击完成.所以完成按钮的点击事件会和change事件产生 冲突,所以我把验证 ...

  10. Fold Change和t分布

    基因表达谱数据 基因表达谱可以用一个矩阵来表示,每一行代表一个基因,每一列代表一个样本(如图1).所有基因的表达谱数据在“gene_exp.txt”文件中存储,第一列为基因的entrez geneid ...

随机推荐

  1. C#:xml操作(待补充)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...

  2. centos7 配置PPTP、L2TP、IPSec服务

    首先,推荐跑下面的脚本: https://github.com/BoizZ/PPTP-L2TP-IPSec-VPN-auto-installation-script-for-CentOS-7 这个脚本 ...

  3. hibernate中对象集合的保存

    一.在java web设计中经常使用对象进行操作,在hibernate中对象集合的保存(一对多) 1需要进行如下步骤: 1) 设计数据表关系 2)引入jar包,需要注意引入数据库connector 3 ...

  4. Jquery.Treeview+Jquery UI制作Web文件预览

    效果图: 前台Html: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="D ...

  5. mysql误删root用户或者忘记root密码解决方法

    解决方法一: 到其他安装了Mysql的服务器(前提是要知道该服务器上Mysql的root用户密 码),打开[Mysql的安装目录/var/mysql],将其中的user.frm.user.MYD.us ...

  6. Linux下UTF-8和GB2312互相转换的函数

    #include<iconv.h> #include <stdio.h> #include<iconv.h>using namespace std; int utf ...

  7. Android 利用fastjson进行json解析

    package com.example.FastJson.util; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.Typ ...

  8. 为什么在c语言中使用gets函数是危险的

      If you have code like this: char s[10]; gets( s ); and you type in more than 10 characters when th ...

  9. 通过CLR API实现C++调用C#代码交互

    对于某些跨平台程序,这也就意味着只能在windows下使用了 不过最近.Net开源或许以后可以跨平台 之前花了一些时间研究COM方式调用,太繁琐不推荐. COM方式调用总结 后来尝试使用CLR C++ ...

  10. [转]软件测试 Top 120 Blog (博客)

    [转]软件测试 Top 120 Blog (博客) 2015-06-08 转自:    软件测试 Top 120 Blog (博客) # Site Author Memo DevelopSense M ...