5

是否可以在 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 小提琴:http: //jsfiddle.net/R62yk/1/

4

1 回答 1

-2

您可以使用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);
于 2013-09-24T07:47:42.443 回答