amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-img doesn't load when initial size is zero (animations)

Open jyn15 opened this issue 8 years ago • 9 comments

What's the issue?

amp-img does not load image when its initial size is zero, even if the size becomes greater than zero later.

How do we reproduce the issue?

The demo shows a rotating card animation. At the first frame the image is rotated 90deg around the Y-axis so it's rendering width is zero. Its transform matrix is animated to rotate the image: https://jsbin.com/zoxafihuco/edit?html,output

The same animation can be achieved by setting opacity to 0 to hide the image at first frame, and reset it to 1 in later frames to show the transform animation. In this case, the image is loaded correctly. https://jsbin.com/belaxurapi/edit?html,output

What browsers are affected?

Chrome 70

Which AMP version is affected?

1811091510240

jyn15 avatar Nov 12 '18 21:11 jyn15

One solutions is having amp-animation force layout on all targets when it initializes. We wouldn't want runtime to try to schedule as animations run. @jridgewell What do you think? (also I don't think we have a way to force layout regardless of visibility yet).

aghassemi avatar Nov 12 '18 23:11 aghassemi

amp-animation needs to invalidate the measurements on the elements it animates.

jridgewell avatar Nov 12 '18 23:11 jridgewell

@jridgewell amp-animation runs off main thread, it can invalidate at the beginning or end of animation but not during (even if it could by running a parallel rAF loop, seems wasteful to invalidate every rAF eventhough nothing about measurements of the element may have changed - we just don't know what keyframes are doing - Passes could be running during the animation remeasuring everything we invalidated).

we should try to make force layout at beginning, invalidate measurements at end work for animation cases.

aghassemi avatar Nov 13 '18 00:11 aghassemi

this also affects native CSS keyframe animation: https://jsbin.com/qocenunode/edit?html,output

is the recommendation to always use amp-animation?

clawr avatar Nov 14 '18 19:11 clawr

We could take the same approach to fix both amp-animation and CSS animations by forcing layout on any targets and revalidating when animation ends. Easier to fix amp-animation than CSS however since we would need to parse and find targets in CSS.

aghassemi avatar Nov 14 '18 21:11 aghassemi

@lannka This came up in the context of the A4A where it is higher priority to fix this. Are you planning to have a different resource manager in A4A given there is no scrolling?

aghassemi avatar Nov 20 '18 18:11 aghassemi

@aghassemi right the problem will be gone in inabox once it has its own resource manager. but it's still a problem in general for amp-animation.

as a tmp work around, would it be acceptable to have 1px width/height with visibility=false?

lannka avatar Nov 27 '18 22:11 lannka

I think runtime detects visibility:false. 1px width/height with opacity=0; pointer-events: none should work though.

aghassemi avatar Nov 28 '18 03:11 aghassemi

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 19 '21 16:12 stale[bot]