首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重绘/回流前触发webkitTransitionEnd

重绘/回流前触发webkitTransitionEnd
EN

Stack Overflow用户
提问于 2016-12-24 07:09:30
回答 0查看 31关注 0票数 0

当我发出ajax请求时,我正在尝试使progressBar改变其宽度,我希望ajax回调仅在progressBar动画结束后执行,我使用以下代码:

css:

代码语言:javascript
复制
#progressBar{
    position: fixed;
    top: 0;
    left: 0;
    background: black;
    height: 3px;
    width: 0;
    transition: width 0.1s linear;
}   

js:

代码语言:javascript
复制
 var endProgressBar = function(){
                var bodyWidth = getComputedStyle(document.body).width;
                var scrolbarWidth = getComputedStyle(progressBar).width;
                console.log(scrolbarWidth  == bodyWidth )   //true but in reality not       
                param.success(req.responseText)
            }

...
        if(lastAffectWidth > 99){
                        progressBar.addEventListener("webkitTransitionEnd", endProgressBar,false);
                        progressBar.addEventListener("Transitionend", endProgressBar,false);
                        progressBar.addEventListener("otransitionend", endProgressBar,false);
                        progressBar.style.width = 100 + '%'
                    }

但在屏幕宽度为100%时调用了回调'endProgressBar‘

我找到的唯一解决方案是添加200ms的setTimeout,但我不喜欢这个解决方案。

我不理解的是,getComputedStyle(document.body).width;返回给我的值与getComputedStyle(progressBar).width的值相同,但实际情况并非如此。

谢谢

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41308799

复制
相关文章

相似问题

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