@@ -623,41 +623,56 @@ Example 1: A colored circle. {#example-1}
623
623
-----------------------------------------
624
624
625
625
<pre class='lang-markup'>
626
- <div id="myElement">
627
- CSS is awesome.
628
- </div>
629
-
626
+ <!DOCTYPE html>
630
627
<style>
631
- #myElement {
632
- --circle-color: red;
628
+ #example {
629
+ --circle-color: deepskyblue;
630
+
633
631
background-image: paint(circle);
634
- }
632
+ font-family: sans-serif;
633
+ font-size: 36px;
634
+ transition: --circle-color 1s;
635
+ }
636
+
637
+ #example:focus {
638
+ --circle-color: purple;
639
+ }
635
640
</style>
636
641
642
+ <textarea id="example">
643
+ CSS is awesome.
644
+ </textarea>
645
+
637
646
<script>
647
+ CSS.registerProperty({
648
+ name: '--circle-color' ,
649
+ syntax: '<color>' ,
650
+ initialValue: 'black' ,
651
+ inherit: false
652
+ });
638
653
CSS.paintWorklet.import('circle.js' );
639
654
</script>
640
655
</pre>
641
656
642
657
<pre class='lang-javascript'>
643
658
// circle.js
644
659
registerPaint('circle' , class {
645
- static get inputProperties() { return ['--circle-color'] ; }
646
- paint(ctx, geom, properties) {
647
- // Change the fill color.
648
- const color = properties.get('--circle-color' );
649
- ctx.fillStyle = color;
650
-
651
- // Determine the center point and radius.
652
- const x = geom.width / 2;
653
- const y = geom.height / 2;
654
- const radius = Math.min(x, y);
655
-
656
- // Draw the circle \o/
657
- ctx.beginPath();
658
- ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
659
- ctx.fill();
660
- }
660
+ static get inputProperties() { return ['--circle-color'] ; }
661
+ paint(ctx, geom, properties) {
662
+ // Change the fill color.
663
+ const color = properties.get('--circle-color' );
664
+ ctx.fillStyle = color.cssText ;
665
+
666
+ // Determine the center point and radius.
667
+ const x = geom.width / 2;
668
+ const y = geom.height / 2;
669
+ const radius = Math.min(x, y);
670
+
671
+ // Draw the circle \o/
672
+ ctx.beginPath();
673
+ ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
674
+ ctx.fill();
675
+ }
661
676
});
662
677
</pre>
663
678
0 commit comments