Skip to content

Commit d83d542

Browse files
committed
Expand on why the controlled value is desirable
1 parent d1666e8 commit d83d542

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.
@@ -231,6 +235,85 @@ img:hover, img:focus {
231235
}
232236
```
233237

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

236319
#### Control Over Iterations

0 commit comments

Comments
 (0)