Skip to content

Commit

Permalink
✨ [Panning media] Use translate3d for transition (#32255)
Browse files Browse the repository at this point in the history
* translate3d

* Add important

* Update unit test.

* Update comment.

* Update date in header.
  • Loading branch information
processprocess committed Jan 28, 2021
1 parent f90e9cb commit c362c4d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 The AMP HTML Authors. All Rights Reserved.
* Copyright 2021 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,15 @@ amp-story-panning-media {
display: flex !important;
justify-content: center !important;
align-items: center !important;
/*
This gives a 3d reference point for the translate3d z value on the child.
A reference point is necessary for the effect of 3d space.
The calculation to convert scale to zoom is:
perspective * (zoom - 1) / zoom
1 is used here to simplify the calculation in updateTransform_ to be:
(zoom - 1) / zoom
*/
perspective: 1px !important;
}

amp-story-panning-media amp-img {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class AmpStoryPanningMedia extends AMP.BaseElement {
const {x, y, zoom} = panningMediaState;
return this.mutateElement(() => {
setImportantStyles(this.ampImgEl_, {
transform: `scale(${zoom}) translate(${x}%, ${y}%)`,
transform: `translate3d(${x}%, ${y}%, ${(zoom - 1) / zoom}px)`,
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ describes.realWin(
await storeService.dispatch(Action.CHANGE_PAGE, {id: 'page1', index: 0});
await afterRenderPromise();
expect(panningMedia.ampImgEl_.style.transform).to.equal(
`scale(${positionValues.zoom}) translate(${positionValues.x}, ${positionValues.y})`
`translate3d(${positionValues.x}, ${positionValues.y}, ${
(positionValues.zoom - 1) / positionValues.zoom
}px)`
);
});
}
Expand Down

0 comments on commit c362c4d

Please sign in to comment.