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

paint() CSS function defines an <image> value generated with a PaintWorklet.

句法

paint(workletName, parameters)
					

where:

workletName

The name of the registered worklet.

parameters

Optional additional parameters to pass to the paintWorklet

范例

Basic usage example

You can pass additional arguments via the CSS paint() function. In this example, we passed two arguments: whether the background-image on a group of list items is filled or just has a stroke outline, and the width of that outline:

li {
   --boxColor: hsla(55, 90%, 60%, 1.0);
   background-image: paint(hollowHighlights, stroke, 2px);
}
li:nth-of-type(3n) {
   --boxColor: hsla(155, 90%, 60%, 1.0);
   background-image: paint(hollowHighlights, filled,  3px);
}
li:nth-of-type(3n+1) {
   --boxColor: hsla(255, 90%, 60%, 1.0);
   background-image: paint(hollowHighlights, stroke, 1px);
}
					

We've included a custom property in the selector block defining a boxColor. Custom properties are accessible to the PaintWorklet.

规范

规范 状态 注释
CSS Painting API Level 1
The definition of 'Paint Notation' 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 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
paint() Chrome 完整支持 65 Edge 完整支持 79 Firefox 不支持 No IE 不支持 No Opera 完整支持 52 Safari 不支持 No WebView Android 完整支持 65 Chrome Android 完整支持 65 Firefox Android 不支持 No Opera Android 完整支持 47 Safari iOS 不支持 No Samsung Internet Android 完整支持 9.2

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改:
  1. CSS
  2. CSS 参考