这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
paint()
CSS
function
defines an
<image>
value generated with a PaintWorklet.
paint(workletName, parameters)
where:
The name of the registered worklet.
Optional additional parameters to pass to the paintWorklet
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. |
工作草案 | 初始定义。 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
完整支持
不支持