html - 如何更改 D3 中的 CSS "animation-delay"属性?

标签 html css d3.js

元素:创建径向进度条以在特定时间启动;即时间启动的进度条。看起来就像径向进度条在互相追逐。

我正在尝试使用 D3 更改 CSS 属性“animation-delay”。我的代码似乎无效。哪些更改会使 D3 代码更改 CSS 属性?

这是一个 D3 代码片段:

<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
//Assume we have a function that calculates the amount of time lapsed since the last departure
//function seconds_since_depart {(return time=(now.time - last.depart.time))}

var time=42;
// a negated time is equal to a progress bar being initiated 42 seconds ago
//but the following line doesn't work
d3.selectAll(".progress__value__a").style({"animationDelay": "-" + time + "s"})

</script>

https://jsfiddle.net/vwetzkjy/

谢谢

最佳答案

此解决方案未使用 d3,但由于您没有数据来驱动您的文档,我不认为您真的需要使用 d3 来实现此目的。

var time = 10;
const selector = `.progress__value__a`
const progressBar = document.querySelector(selector)
progressBar.style.animationDelay = `${time*-1}s`
body {
  background-color: #f9faff;
  overflow: hidden;
}

.demo {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}


.progress {
  transform: rotate(-90deg);
}

.progress__value {
  stroke-dasharray: 766.5486;
  stroke-dashoffset: 0;
  animation: progress 39.86s linear infinite;
}

.progress__value__a {
  stroke-dasharray: 766.5486;
  stroke-dashoffset: 0;
  animation: progress 39.86s linear infinite;
}


@keyframes progress {
  0% {
    stroke-dasharray: 0 766.5486;
  }
}
<div class="demo">
  <svg class="progress" height="500" width="500">
    <circle cx="260" cy="230" r="122" stroke="#e6e6e6" stroke-width="4" fill="white" />
    <circle class="progress__value" cx="260" cy="230" r="122" stroke="#009900" stroke-width="5" opacity=".71" fill="#f9faff" stroke-dasharray="766.5486" stroke-dashoffset="766.5486" />
    <circle class="progress__value__a" cx="260" cy="230" r="122" stroke="#ff3a00" stroke-width="5" opacity=".71" fill="#f9faff" stroke-dasharray="766.5486" stroke-dashoffset="766.5486" />
  </svg>
</div>

jsfiddle

关于html - 如何更改 D3 中的 CSS "animation-delay"属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54527042/

相关文章:

jquery - 使用 jquery 隐藏表的列/td

html - 是什么导致 ie8 中标题和主菜单开始之间出现白色间隙

javascript - 编写 Javascript 函数以在单击按钮时更改网页的亮度

javascript - Angular 6 中具有相应组件的子路由

javascript - 使用 Selenium 获取 DOM 中(而不是 HTML)中的 (d3) 元素的属性

javascript - D3.js - 使用 json 中的嵌套数组绘制图像

javascript - 如何对 d3 中的形状选择进行排序

css - 相互使用 Grid960 文本

html - 将 UL 列表拉伸(stretch)为水平导航栏,间距均匀...外边距也有空格

ios - Fabric js 文本字符在 iPhone 和 iPad 上出现乱码