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

the*_*fon 5 javascript css 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
Run Code Online (Sandbox Code Playgroud)

但是这仅在 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>
Run Code Online (Sandbox Code Playgroud)

CSS

td {
    transition: all 3s linear;
}
Run Code Online (Sandbox Code Playgroud)

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);
Run Code Online (Sandbox Code Playgroud)

JS小提琴: http : //jsfiddle.net/R62yk/1/

Sim*_*one -2

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

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);
Run Code Online (Sandbox Code Playgroud)