是否有可能在Javascript中的css3转换期间获取目标计算的css属性值?

时间:2013-09-24 07:25:58

标签: javascript css3 css-transitions

在Javascript的css3过渡期间是否可以获得目标(最终)计算的css属性值?

我找到了这个答案: Is it possible to get the target css property value during a css3 transition in Javascript?

所以,我可以把它作为

document.getElementById('transition_div').style.width

但这只适用于在css中指定目标css属性的情况。我需要得到动态计算的目标属性值 - 未在CSS中指定。

HTML:

<table>
    <tr>
        <td id="cell-1">CELL 1</td>
        <td id="cell-2">CELL 2</td>
        <td id="cell-3">CELL 3 some text</td>
    <tr>
<table>

CSS

td {
    transition: all 3s linear;
}

JS

setTimeout(function() { //let's browser draw initial state
    document.getElementById("cell-1").style["min-width"] = "300px"; //resize one of cells

    setTimeout(function() {
        //NOW, a second later, transition is in progress

        //HOW to get target width of #cell-3 ????

    }, 1000);

}, 0);

JS FIDDLE: http://jsfiddle.net/R62yk/1/

1 个答案:

答案 0 :(得分:-1)

您可以使用window.getComputedStyle。试试这个:

setTimeout(function() { //let's browser draw initial state
    document.getElementById("cell-1").style["min-width"] = "300px"; //resize one of cells

    setTimeout(function() {
        //NOW, a second later, transition is in progress

        //HOW to get target width of #cell-3 ????
        var cell = document.getElementById("cell-3"),
            width = getComputedStyle(cell,null).getPropertyValue("width");
        // computed width is 206px
    }, 1000);

}, 0);