这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

CanvasRenderingContext2D .scrollPathIntoView() method of the Canvas 2D API scrolls the current or given path into view. It is similar to Element.scrollIntoView() .

句法

void ctx.scrollPathIntoView();
void ctx.scrollPathIntoView(path);
					

参数

path
Path2D path to use.

范例

Using the scrollPathIntoView method

此范例演示 scrollPathIntoView() 方法。

HTML

<canvas id="canvas"></canvas>
					

JavaScript

const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.fillRect(10, 10, 30, 30);
ctx.scrollPathIntoView();
					

Edit the code below to see your changes update live in the canvas:

Playable code
<canvas id="canvas" width="400" height="200" class="playable-canvas">
<input id="button" type="range" min="1" max="12">
</canvas>
<div class="playable-buttons">
  <input id="edit" type="button" value="Edit" />
  <input id="reset" type="button" value="Reset" />
</div>
<textarea id="code" class="playable-code">
ctx.beginPath();
ctx.rect(10, 10, 30, 30);
ctx.scrollPathIntoView();</textarea>
					
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var textarea = document.getElementById("code");
var reset = document.getElementById("reset");
var edit = document.getElementById("edit");
var code = textarea.value;
function drawCanvas() {
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  eval(textarea.value);
}
reset.addEventListener("click", function() {
  textarea.value = code;
  drawCanvas();
});
edit.addEventListener("click", function() {
  textarea.focus();
})
textarea.addEventListener("input", drawCanvas);
window.addEventListener("load", drawCanvas);
					

规范

规范 状态 注释
HTML 实时标准
The definition of 'CanvasRenderingContext2D.scrollPathIntoView' in that specification.
实时标准

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
scrollPathIntoView Chrome Yes Disabled
Yes Disabled
Disabled This feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge ≤79 Disabled
≤79 Disabled
Disabled From version ≤79: this feature is behind the Experimental Web Platform Features preference.
Firefox No IE No Opera Yes Safari No WebView Android Yes Chrome Android Yes Firefox Android No Opera Android No Safari iOS No Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改: