Skip to content

Commit 47cd2fe

Browse files
committed
Expand on why the controlled value is desirable
1 parent 6b6983d commit 47cd2fe

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed

image-animation-property/README.md

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Authors: Florian Rivoal, Lea Verou
1313
1. [Non-goals](#non-goals)
1414
4. [Proposed Solution](#proposed-solution)
1515
1. [Sample Code Snippets](#sample-code-snippets)
16-
2. [Possible Extensions](#possible-extensions)
16+
2. [Discussion of the `controlled` Value](#discussion-of-the-controlled-value)
17+
3. [Possible Extensions](#possible-extensions)
1718
1. [Control Over Iterations](#control-over-iterations)
1819
2. [Longhands And Further Controls](#longhands-and-further-controls)
1920
3. [Control Over the Paused State](#control-over-the-paused-state)
@@ -61,6 +62,7 @@ For example:
6162
* Turn off autoplay for decorative images when `prefers-reduced-motion` is on,
6263
while keeping animations on for those that are part of UI interactions
6364

65+
<p id=there-to-stay>
6466
In some cases,
6567
this can already be done using alternatives to animated images,
6668
such as CSS animations, SVG, or `<video>` elements,
@@ -196,6 +198,7 @@ Turn off autoplay on all images, showing UI controls for playback on animatable
196198
```
197199
Note that this can be applied just as easily by a site's author, a [web extension](https://w3c.github.io/webextensions/specification/), a user-stylesheet, without any modification to—or knowledge of—the site's markup patterns. Other uses could include a web-based email-client using this to keep animated images under control in HTML email.
198200

201+
<p id=ex-on-demand>
199202
Same as above, in response to a [user request for reduced motion](https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion):
200203
```css
201204
@media (prefers-reduced-motion) {
@@ -216,6 +219,7 @@ and offering on-demand playback for relevant parts of the content.
216219
}
217220
```
218221

222+
<p id=ex-simple-controls>
219223
The browser-provided controls are not the only way to start a paused image.
220224
Elaborate controls can obviously be build with custom markup and script,
221225
but simple cases can be done declaratively.
@@ -245,6 +249,85 @@ Interesting effects can easily be achieved in combination with other CSS:
245249
.carousel img:snapped { image-animation: play; }
246250
```
247251

252+
### Discussion of the `controlled` Value
253+
254+
The `controlled` value presented above is more complex than the rest,
255+
so it is worth taking some time to explain
256+
why it is a reasonable and important part of this proposal.
257+
258+
<dl>
259+
<dt>Is it OK to have a CSS property affect UI?
260+
<dd>
261+
There is precedent for CSS properties affecting the presence of UI controls on elements:
262+
[`resise`](https://www.w3.org/TR/css-ui-3/#resize),
263+
[`overflow: scroll` or `overflow: auto `](https://www.w3.org/TR/css-overflow-3/#overflow-control).
264+
265+
<dt>Do we need any such thing at all?
266+
<dd>
267+
As discussed [in the example above](#ex-simple-controls),
268+
a simple interaction model can be built without any additional markup nor JS;
269+
and certainly arbitrary UI can be built if you allow for extra markup and JS.
270+
271+
However, in the general case, authors have no way of knowing which images are static and which are animatable.
272+
Without this knowledge, the choice is either to provide no controls at all,
273+
or controls even on static images that don't need it.
274+
275+
Enabling authors (and web-extension developers, and writers of user stylesheets)
276+
to disable by default unwanted animations,
277+
while keeping the ability to view them on demand,
278+
on existing content,
279+
is an important motivation for this feature.
280+
This is trivially achieved with this [previously discussed](#ex-on-demand) rule,
281+
but out of reach otherwise:
282+
```css
283+
@media (prefers-reduced-motion) {
284+
:root { image-animation: controlled; }
285+
}
286+
```
287+
288+
<dt>Couldn't we use pseudo-classes instead?
289+
<dd>
290+
Something like an `:animatable` pseudo class would solve the above information problem,
291+
and authors could build their UI from there.
292+
But would it be better?
293+
We should make easy things easy,
294+
and provide a good user experience for users.
295+
The example below shows what a typical browser-provided UI can be expected to look like,
296+
and replicating that manually,
297+
with good accessibility,
298+
would not be easy.
299+
300+
<img src="../images-in-video/media/wa-animated-image.gif" alt="Paused image with a centered overlayed triangular 'play' button, visible whether or not the user hovers. When pressed, the image animation starts, and the button turns into a double-bar 'pause' button, visible while the image is hovered, but disapearing if the cursor is moved away">
301+
302+
<dt>Shouldn't this be done in markup instead?
303+
<dd>
304+
Arguably that should be possible too.
305+
In [a different explainer](../images-in-video/README.md),
306+
we argue that the ability to use animated image formats in the `<video>` element would address a number of use cases.
307+
Maybe animatable images in `<img>` elements should never have existed,
308+
but they do,
309+
and [for a number of reasons they are here to stay](#here-to-stay).
310+
And as discussed [in the intro](user-needs--use-cases),
311+
due to preferences and to WCAG reasons,
312+
users need to be able to chose to turn such animations off
313+
while keeping the ability to opt into viewing them individually.
314+
`image-animation: controlled` can be applied to existing markup and user-generated content
315+
in a way that changing markup cannot.
316+
317+
More over, styling can declaratively respond to `@media (prefers-reduced-motion)`,
318+
while no such solution is available directly on markup.
319+
320+
Adding `controls` or `noautoplay` attributes to the `<img>` element
321+
(along with related APIs)
322+
[might be worth looking into as well](../images-in-video/README.md#making-img-andor-picture-media-elements),
323+
but the same observations apply.
324+
If we were to add both `image-animation: controlled`
325+
and new markup-level capabilities to the `<img>` element,
326+
the interaction would need to be specified,
327+
but that is just as true as with other values.
328+
329+
</dl>
330+
248331
### Possible Extensions
249332

250333
#### Control Over Iterations

0 commit comments

Comments
 (0)