Skip to content

Commit d536514

Browse files
committed
[css-images] Add an elementSources example.
1 parent 318d069 commit d536514

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

css-images/Overview.html

+20
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,26 @@ <h4 class="heading settled heading" data-level=3.4.2 id=elementmap><span class=s
870870
it’s then looked for in the document as normal.
871871
</ul>
872872

873+
<div class=example>
874+
For example, fancy animating backgrounds can be done with an external canvas:
875+
876+
<pre> &lt;script&gt;
877+
var bg = document.createElement('canvas');
878+
bg.height = 200;
879+
bg.width = 1000;
880+
drawFancyBackground(bg);
881+
CSS.elementSources.set('fancy', bg);
882+
&lt;/script&gt;
883+
&lt;style&gt;
884+
h1 {
885+
background-image: element(#fancy);
886+
}
887+
&lt;/style&gt;
888+
</pre>
889+
<p> As the "fancy" canvas is drawn into and animated,
890+
the backgrounds of all the H1 elements will automatically update in tandem.
891+
</div>
892+
873893
<h4 class="heading settled heading" data-level=3.4.3 id=element-cycles><span class=secno>3.4.3 </span><span class=content>
874894
Cycle Detection</span><a class=self-link href=#element-cycles></a></h4>
875895

css-images/Overview.src.html

+22
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,28 @@ <h4 id='elementmap'>
840840
it's then looked for in the document as normal.
841841
</ul>
842842

843+
<div class='example'>
844+
For example, fancy animating backgrounds can be done with an external canvas:
845+
846+
<pre>
847+
&lt;script>
848+
var bg = document.createElement('canvas');
849+
bg.height = 200;
850+
bg.width = 1000;
851+
drawFancyBackground(bg);
852+
CSS.elementSources.set('fancy', bg);
853+
&lt;/script>
854+
&lt;style>
855+
h1 {
856+
background-image: element(#fancy);
857+
}
858+
&lt;/style>
859+
</pre>
860+
861+
As the "fancy" canvas is drawn into and animated,
862+
the backgrounds of all the H1 elements will automatically update in tandem.
863+
</div>
864+
843865
<h4 id='element-cycles'>
844866
Cycle Detection</h4>
845867

0 commit comments

Comments
 (0)