在本文中,作者声明不需要永久存储样式将更改css样式文件will-change: transform;
,而应使用javascript动态添加
Аlso 作者示例脚本:
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';
}
我可以使用这个脚本,他是否对我有用?
$('.my_class')
.mouseenter(function() {
$(this).css("will-change", "transform");
})
.mouseleave(function() {
$(this).removeAttr("style");
});
我很高兴听到有关如何有效利用风格的建议will-change