d3-transition
过渡是一种类似于 选择 的界面,用于对 DOM 的更改进行动画处理。过渡不会立即应用更改,而是在给定的持续时间内,将 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");过渡支持大多数选择方法(例如使用 transition.attr 和 transition.style 代替 selection.attr 和 selection.style),但并非所有方法都受支持;例如,你必须在过渡开始之前 append 元素或 bind data。提供了 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.
为了计算中间状态,转换利用各种内置插值器。颜色、数字和变换会被自动检测到。包含数字的字符串也会被检测到,这在许多样式(例如填充或字体大小)和路径中很常见。要指定自定义插值器,请使用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: