d3-transition
过渡是类似 selection 的接口,用于动画化 DOM 的变化。transitions 不会立即应用更改,而是在给定的持续时间内将 DOM 从当前状态平滑地插入到所需的目标状态。
¥A transition is a selection-like interface for animating changes to the DOM. Instead of applying changes instantaneously, transitions smoothly interpolate the DOM from its current state to the desired target state over a given duration.
要应用过渡,请选择元素,调用 selection.transition,然后进行所需的更改。例如:
¥To apply a transition, select elements, call selection.transition, and then make the desired changes. For example:
d3.select("body")
.transition()
.style("background-color", "red");
Transitions support most selection methods (such as transition.attr and transition.style in place of selection.attr and selection.style), but not all methods are supported;例如,在转换开始之前,你必须 append 个元素或 绑定数据 个元素。提供了一个 transition.remove 运算符,以便在转换结束时方便地删除元素。
¥Transitions support most selection methods (such as transition.attr and transition.style in place of selection.attr and selection.style), but not all methods are supported; for example, you must append elements or bind data before a transition starts. A transition.remove operator is provided for convenient removal of elements when the transition ends.
为了计算中间状态,转换利用了各种 内置插值器。颜色、numbers 和 transforms 会被自动检测。嵌入数字的 字符串 也会被检测到,这在许多样式(例如填充或字体大小)和路径中很常见。要指定自定义插值器,请使用 transition.attrTween、transition.styleTween 或 transition.tween。
¥To compute intermediate state, transitions leverage a variety of built-in interpolators. Colors, numbers, and transforms are automatically detected. Strings with embedded numbers are also detected, as is common with many styles (such as padding or font sizes) and paths. To specify a custom interpolator, use transition.attrTween, transition.styleTween or transition.tween.
请参阅以下之一:
¥See one of: