w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.52k stars 673 forks source link

[css-images-4] Add way to adjust playback speed of animated images, pause animating image #9396

Open SerenaLynas opened 1 year ago

SerenaLynas commented 1 year ago

Currently there is no way to pause/adjust the playback speed of animating GIFs/webps. I suggest adding descriptors something along the lines of the following:

image-animation-speed: auto | <time-percentage>

Multiply the natural playback speed of the image by this value, speeding it up (> 100%), slowing it down (< 100%), pausing it (= 0), or reversing it (< 0%).

image-animation-clip-start: <time-percentage>

Clip off the specified amount of time from the start of the animation, so those frames are skipped. The duration decreases by this value.

image-animation-clip-end: <time-percentage>

Clip off the specified amount of time from the end of the animation, so those frames are skipped. The duration decreases by this value.

image-animation-duration: auto | <time>

Makes the animation play for the specified duration.

image-animation-paused-at: <time-percentage>

Alternative name: image-animation-stopped-at Image is paused at the fame at the given time (based on the natural playback speed). If a number or a percent, the image is paused at the position that portion through the image's animation (so 1 or 100% is the last frame of the animation, and 0 or 0% is the first. 50% is the middle frame). If this property is later removed from the image, the image will continue animating from this frame (it won't start over).

Adding these properties would allow web developers to control the playback of GIF and Webp images, which is currently impossible.

samuelbradshaw commented 1 year ago

This is an interesting idea. However, would it be better to update the img element to handle this in HTML? Related (for audio/video elements): https://developer.mozilla.org/en-US/docs/Web/Guide/Audio_and_video_delivery#specifying_playback_range

bleper commented 1 year ago

Among other things with this, it will be possible to easily improve web accessibility for authors by pausing animated images, which today requires the overhead of providing an alternative non-animated image for a reduced motion media query. User agents or users themselves, through a style sheet, will be able to adapt the movement to the needs of the user in a declarative way.

easrng commented 4 months ago

This seems like a dupe of #1615

aeharding commented 3 weeks ago

This is an interesting idea. However, would it be better to update the img element to handle this in HTML? Related (for audio/video elements): developer.mozilla.org/en-US/docs/Web/Guide/Audio_and_video_delivery#specifying_playback_range

That would be interesting. So for images - <img src="https://example.com/animated_image.webp#t=,0">?