You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: css-animations/Overview.bs
+60Lines changed: 60 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1034,6 +1034,66 @@ The <code>findRule</code> method</h4>
1034
1034
1035
1035
No Exceptions
1036
1036
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
<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 <spanclass="css">from</span> maps to 0% and <spanclass="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
0 commit comments