首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Javascript中的css3转换过程中,能够得到计算出的目标css属性值吗?

在Javascript中的css3转换过程中,能够得到计算出的目标css属性值吗?
EN

Stack Overflow用户
提问于 2013-09-24 07:25:57
回答 1查看 702关注 0票数 5

在Javascript中的css3转换过程中,能够得到目标(最终)计算的css属性值吗?

我找到了这个答案:在Javascript中的css3转换过程中,可以获得目标css属性值吗?

所以,我可以

代码语言:javascript
复制
document.getElementById('transition_div').style.width

但这只在css中指定目标css属性时才能起作用。我需要得到目标属性值,它是动态计算的-没有在CSS中指定。

HTML:

代码语言:javascript
复制
<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

代码语言:javascript
复制
td {
    transition: all 3s linear;
}

JS

代码语言:javascript
复制
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/

EN

回答 1

Stack Overflow用户

发布于 2013-09-24 07:47:42

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

代码语言:javascript
复制
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);
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18975412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档