Skip to content

Commit 1e768ae

Browse files
author
Sylvain Galineau
committed
Add DOM interface example
1 parent 6d3b2f5 commit 1e768ae

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

css-animations/Overview.bs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,66 @@ The <code>findRule</code> method</h4>
10341034

10351035
No Exceptions
10361036

1037+
<div class='example'>
1038+
For example, given the following animation:
1039+
<pre>
1040+
1041+
@keyframes colorful-diagonal-slide {
1042+
1043+
from {
1044+
left: 0;
1045+
top: 0;
1046+
}
1047+
1048+
10% {
1049+
background-color: blue;
1050+
}
1051+
1052+
10% {
1053+
background-color: green;
1054+
}
1055+
1056+
25%, 75% {
1057+
background-color: red;
1058+
}
1059+
1060+
100% {
1061+
left: 100px;
1062+
top: 100px;
1063+
}
1064+
1065+
}
1066+
</pre>
1067+
1068+
Assuming the variable <code>anim</code> holds a reference to a CSSKeyframesRule object for this animation, then:
1069+
1070+
<pre>
1071+
anim.deleteRule('10%');
1072+
var tenPercent = anim.findRule('10%');
1073+
</pre>
1074+
1075+
will start by deleting the last 10% rule i.e. the green background color rule; then find the remaining blue background rule and return it into <code>tenPercent</code>.
1076+
1077+
The following:
1078+
<pre>
1079+
var red = anim.findRule('75%');
1080+
</pre>
1081+
1082+
will set <code>red</code> to <code>null</code>. The full selector for the red background color rule must be used instead:
1083+
1084+
<pre>
1085+
var red = anim.findRule('25%,75%');
1086+
</pre>
1087+
1088+
Since ''from'' maps to 0% and ''to'' maps to 100%, we can find these rules using either value:
1089+
1090+
<pre>
1091+
var from = anim.findRule('0%'); // Returns from { left: 0; top: 0; } rule
1092+
var to = anim.findRule('to'); // Returns 100% { left: 100px; top: 100px; } rule
1093+
</pre>
1094+
</div>
1095+
1096+
10371097

10381098

10391099

css-animations/Overview.html

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,83 @@ <h4 class="heading settled" data-level="6.3.5" id="interface-csskeyframesrule-fi
17621762

17631763
<p>No Exceptions</p>
17641764

1765+
1766+
<div class="example">
1767+
For example, given the following animation:
1768+
1769+
<pre>
1770+
@keyframes colorful-diagonal-slide {
1771+
1772+
from {
1773+
left: 0;
1774+
top: 0;
1775+
}
1776+
1777+
10% {
1778+
background-color: blue;
1779+
}
1780+
1781+
10% {
1782+
background-color: green;
1783+
}
1784+
1785+
25%, 75% {
1786+
background-color: red;
1787+
}
1788+
1789+
100% {
1790+
left: 100px;
1791+
top: 100px;
1792+
}
1793+
1794+
}
1795+
</pre>
1796+
1797+
1798+
1799+
<p>Assuming the variable <code>anim</code> holds a reference to a CSSKeyframesRule object for this animation, then:</p>
1800+
1801+
1802+
1803+
<pre>anim.deleteRule('10%');
1804+
var tenPercent = anim.findRule('10%');
1805+
</pre>
1806+
1807+
1808+
1809+
<p>will start by deleting the last 10% rule i.e. the green background color rule; then find the remaining blue background rule and return it into <code>tenPercent</code>.</p>
1810+
1811+
1812+
1813+
<p>The following:</p>
1814+
1815+
1816+
<pre>var red = anim.findRule('75%');
1817+
</pre>
1818+
1819+
1820+
1821+
<p>will set <code>red</code> to <code>null</code>. The full selector for the red background color rule must be used instead:</p>
1822+
1823+
1824+
1825+
<pre>var red = anim.findRule('25%,75%');
1826+
</pre>
1827+
1828+
1829+
1830+
<p>Since <span class="css">from</span> maps to 0% and <span class="css">to</span> maps to 100%, we can find these rules using either value:</p>
1831+
1832+
1833+
1834+
<pre>var from = anim.findRule('0%'); // Returns from { left: 0; top: 0; } rule
1835+
var to = anim.findRule('to'); // Returns 100% { left: 100px; top: 100px; } rule
1836+
</pre>
1837+
1838+
1839+
</div>
1840+
1841+
17651842

17661843

17671844

0 commit comments

Comments
 (0)