【问题标题】:d3.js transition is not working with property methodd3.js 过渡不适用于属性方法
【发布时间】:2015-06-03 04:00:00
【问题描述】:

我正在学习 d3.js。在下面的脚本中,当 selection.property() 被链接时,selection.transition() 似乎不起作用,虽然它在 selection.property() 被放入 transition().each() 时有效。难道我做错了什么?或者,这是 transition() 的规范吗?

<input class="property_transition" type="checkbox">Property Transition Test</input><br>
<input class="property_transition" type="checkbox">Property Transition Test</input><br>
<input class="property_transition" type="checkbox">Property Transition Test</input><br>
<input class="property_transition" type="checkbox">Property Transition Test</input><br>

<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
    var elements = d3.selectAll(".property_transition");
    elements
        .transition()//.delay(function(d,i) { return i/elements.length *50; })
            .property("checked", true); // <== This is NOT working.
            //.each("end", function() { d3.select(this).property("checked",true); }); // <== This works!!!
</script>

有了这个脚本, Chrome浏览器给出:

未捕获的类型错误:elements.transition(...).property 不是 功能

IE11 给出:

对象不支持属性或方法'property'

谢谢,

【问题讨论】:

  • 转换二进制值实际上没有意义。你应该简单地设置它。
  • 我同意你的看法。它用于从上到下检查多个复选框的视觉效果。我喜欢这种效果,很抱歉,这个问题主要是出于我对 d3 工作原理的好奇:)
  • .property() 不是你可以在 D3 中转换的东西,所以这是简短的回答 :)
  • 谢谢!你让我免于浪费时间,因为我太喜欢玩弄自己的好奇心了。

标签: google-chrome d3.js internet-explorer-11


【解决方案1】:

简短的回答是 .property() 不是您可以在 D3 中转换的东西,特别是它不提供相应的功能(正如您在 Chrome 中收到的错误消息所暗示的那样)。

一般来说,转换二进制属性并没有什么意义——中间值是什么?

【讨论】:

    猜你喜欢
    • 2021-10-23
    • 2021-08-07
    • 1970-01-01
    • 2014-10-14
    • 2020-04-30
    • 2014-09-14
    • 2020-09-23
    • 2012-07-07
    • 2014-12-31
    相关资源
    最近更新 更多