Is it possible to get the target calculated css property value during a css3 transition in Javascript?

荒凉一梦 提交于 2020-01-01 12:07:10

问题


Is it possible to get the target (final) calculated css property value during a css3 transition in Javascript?

I found this answer: Is it possible to get the target css property value during a css3 transition in Javascript?

So, I can get it as

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

BUT this works only when target css property is specified in css. I need get target property value which is calculated dynamicaly - not specified in 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:


You can use window.getComputedStyle. Try this:

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);


来源:https://stackoverflow.com/questions/18975412/is-it-possible-to-get-the-target-calculated-css-property-value-during-a-css3-tra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!