【问题标题】:Why does style.strokeDashoffset always returns empty, even when set?为什么 style.strokeDashoffset 总是返回空,即使设置了?
【发布时间】:2017-05-18 22:25:20
【问题描述】:

所以我尝试使用 javascript 增加 svg 的 stroke-dashoffset css,但我无法获得任何 svg 路径的当前 stroke-dashoffset。

这是一个jsfiddle,通过这种方式在控制台中可见:

setInterval(function(){
    path = document.getElementById("path1");
    console.log(path.style.strokeDashoffset)
},50)

如何获得路径的计算当前 stroke-dashoffset 值?

【问题讨论】:

    标签: javascript css svg


    【解决方案1】:

    你必须使用 getComputedStyle() 函数:

    setInterval(function(){
      path = document.getElementById("path1");
      console.log(window.getComputedStyle(path).strokeDashoffset)
    },50)
    

    http://jsfiddle.net/46cmu71t/39/

    【讨论】:

      猜你喜欢
      • 2019-12-05
      • 2021-08-03
      • 2014-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-11
      • 1970-01-01
      相关资源
      最近更新 更多