大网数据广告活动
Web 标准与前端开发

DelegatedInkTrailPresenter: updateInkTrailStartPoint() method

· 52CE 我爱测

The **`updateInkTrailStartPoint()`** method of the DelegatedInkTrailPresenter interface indicates which PointerEvent was used as the last rendering point for the current frame, allowing the OS-level compositor to render a delegated ink trail ahead of the next pointer event being

Ink API

The updateInkTrailStartPoint() method of the DelegatedInkTrailPresenter interface indicates which PointerEvent was used as the last rendering point for the current frame, allowing the OS-level compositor to render a delegated ink trail ahead of the next pointer event being dispatched.

Syntax

updateInkTrailStartPoint(event, style)

Parameters

  • event
    • : A PointerEvent.
  • style
    • : An object defining the trail style, which contains the following properties:
      • color
        • : A String containing a valid CSS color code, indicating the color the presenter will use when rendering the ink trail.
      • diameter
        • : A number representing the diameter the presenter will use when rendering the ink trail.

Return value

undefined.

Exceptions

  • Error DOMException
    • : An error is thrown and the operation is aborted if the:
      • color property does not contain a valid CSS color code.
      • diameter property is not a number or less than 1.
      • DelegatedInkTrailPresenter.presentationArea element is removed from the document before or during rendering.

Examples

Drawing an ink trail

In this example, we draw a trail onto a 2D canvas. Near the start of the code, we call Ink.requestPresenter(), passing it the canvas as the presentation area for it to take care of and storing the promise it returns in the presenter variable.

Later on, in the pointermove event listener, the new position of the trailhead is drawn onto the canvas each time the event fires. In addition, the DelegatedInkTrailPresenter object returned when the presenter promise fulfills has its updateInkTrailStartPoint() method invoked; this is passed:

  • The last trusted pointer event representing the rendering point for the current frame.
  • A style object containing color and diameter settings.

The result is that a delegated ink trail is drawn ahead of the default browser rendering on the app's behalf, in the specified style, until the next time it receives a pointermove event.

HTML

<canvas id="my-canvas"></canvas>
<div id="div">Delegated ink trail should match the color of this div.</div>

CSS

div {
  background-color: lime;
  position: fixed;
  top: 1rem;
  left: 1rem;
}

JavaScript

const canvas = document.getElementById("my-canvas");
const ctx = canvas.getContext("2d");
const presenter = navigator.ink.requestPresenter({ presentationArea: canvas });
let moveCnt = 0;
let style = { color: "lime", diameter: 10 };

function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

canvas.addEventListener("pointermove", async (evt) => {
  const pointSize = 10;
  ctx.fillStyle = style.color;
  ctx.fillRect(evt.pageX, evt.pageY, pointSize, pointSize);
  if (moveCnt === 20) {
    const r = getRandomInt(0, 255);
    const g = getRandomInt(0, 255);
    const b = getRandomInt(0, 255);

    style = { color: `rgb(${r} ${g} ${b} / 100%)`, diameter: 10 };
    moveCnt = 0;
    document.getElementById("div").style.backgroundColor =
      `rgb(${r} ${g} ${b} / 60%)`;
  }
  moveCnt += 1;
  await presenter.updateInkTrailStartPoint(evt, style);
});

window.addEventListener("pointerdown", () => {
  ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
});

canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

Result

Drawing an ink trail

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。