javascript - 如何更改dur属性?
问题描述
根据当前时间,我需要将球放在一条线上的位置。考虑使用在时钟上定位分针。
我在 Mozilla 网站上搜索了getElementbyId
文档,看看是否有像“animationdelay”这样的属性。我尝试阅读 animateMotion id 的属性getElementbyId
。
<svg class="progress" height="500" width="500"
xmlns="http://www.w3.org/2000/svg" version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink">
<path id="link" d=" M 50,50 L 500,100 " fill="none"/>
<circle cx="" cy="" r=5>
<!-- Define the motion path animation -->
<animateMotion id="alterid" dur="21s" repeatCount="indefinite"
keyPoints=".7;0" keyTimes="0;1" calcMode="linear">
<mpath xlink:href="#link"/>
</animateMotion>
</circle>
</svg>
x1=document.getElementById("alterid");
x1.dur="222s";
https://codepen.io/anon/pen/ydKjgL#anon-login
在上面的代码中,由于 x1.dur 代码,我预计球动画需要 222 秒,而不是动画需要 21 秒;即持续时间保持不变。如何动态更改持续时间?
解决方案
您可以使用 D3 轻松访问 DOM 元素。
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
d3.select("animateMotion")
.attr("dur", '222s')
</script>
推荐阅读
- gitahead - GitAhead - 你能在提交时添加一个“修改”复选框吗?
- javascript - 在 Signalr Core 中调用 Ajax 函数
- swift - 如何在 Swift 字典中找到前 3 个最大值?
- reactjs - Google Firebase Auth 在 Netlify 上失败,但在本地服务器上工作
- c++ - 为什么我的应用在 sudo 模式下更加丰富多彩?
- android - Android MLKit 仅在屏幕中心扫描二维码
- android - 我正在提供 Drawable 类对象,但参数给出错误消息,“必需类型 int 提供 Drawable”
- angular - 在 mat-autocomplete 上选择一个值会清除该值,然后显示完整列表?
- c# - Fluent Migrator 在错误的数据库中创建了表版本信息
- javascript - 将数组转换为 ES6 可迭代