【问题标题】:Does width in percentage % help performance in an animation?百分比宽度是否有助于动画的性能?
【发布时间】:2013-06-25 04:42:20
【问题描述】:

如果我有一个固定宽度的父 div 和子 div,

<div id="parent">
    <div class="children"></div>
    <div class="children"></div>
    <div class="children"></div>
    <div class="children"></div>
</div>

.

#parent {
    width:100px;
}

我想为父母的宽度设置动画(所以孩子的宽度也会被动画)。


为孩子设置百分比宽度是否更好:

.children {
    width:25%;
    float:left;
}

还有一个动画元素:

$('#parent').animate({
    width : 0
}, 1000);

或为孩子设置固定宽度(注意 px):

.children {
    width:25px;
    float:left;
}

并为所有 div 设置动画:

$('#parent,.children').animate({
    width : 0
}, 1000);

或者这根本不重要,因为最终所有东西都会以某种方式调整大小?

【问题讨论】:

    标签: css performance jquery-animate percentage fixed-width


    【解决方案1】:

    您使用的尺寸单位对动画的性能没有影响。

    但是,如果你真的关心性能,你应该考虑使用 css3 转换而不是 jQuery(更多信息在这里:http://dev.opera.com/articles/view/css3-vs-jquery-animations/)。

    无论如何,我怀疑在你的情况下性能提升会很明显。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-10
      • 2012-07-14
      • 2012-08-05
      • 2018-09-16
      • 2012-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多