--- title: CanvasRenderingContext2D.scrollPathIntoView() slug: Web/API/CanvasRenderingContext2D/scrollPathIntoView translation_of: Web/API/CanvasRenderingContext2D/scrollPathIntoView ---
CanvasRenderingContext2D
.scrollPathIntoView()
是 Canvas 2D API 将当前或给定的路径滚动到窗口的方法。类似于 {{domxref("Element.scrollIntoView()")}}。
void ctx.scrollPathIntoView(); void ctx.scrollPathIntoView(path);
path
这是一段使用 scrollPathIntoView
方法的简单的代码片段。
<canvas id="canvas"></canvas>
var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); ctx.beginPath(); ctx.fillRect(10, 10, 30, 30); ctx.scrollPathIntoView();
修改下面的代码并在线查看 canvas 的变化:
{{ EmbedLiveSample('Playable_code', 700, 360) }}
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "scripting.html#dom-context-2d-scrollpathintoview", "CanvasRenderingContext2D.scrollPathIntoView")}} | {{Spec2('HTML WHATWG')}} |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}}[1] | {{CompatNo}} {{bug(1120401)}} |
{{CompatNo}} | {{CompatVersionUnknown}} | {{CompatNo}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatNo}} {{bug(1120401)}} |
{{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
ExperimentalCanvasFeatures
为 true
进行启用。