-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add amp-fx="fade-in" - scroll triggered timed animation. #14351
Conversation
…ccordingly as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alanorozco could you PTAL?
I have highlighted the sections that need review. Since #14276 hasn't landed yet the diff has changes made in this PR and that one. Will rebase once #14276 has landed.
@@ -0,0 +1,112 @@ | |||
<!doctype html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New compared to #14276
@@ -134,6 +128,10 @@ class AmpFxCollection { | |||
|
|||
// Validate that we support the requested fx types. | |||
fxTypes.forEach(fxType => { | |||
if (fxType == FxType.FADE_IN) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New compared to #14276
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be moved to the preset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -0,0 +1,47 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New compared to #14276
} | ||
}, | ||
}, | ||
'fade-in': { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New compared to #14276
import {Services} from '../../../../src/services'; | ||
import {dev, user} from '../../../../src/log'; | ||
import {convertEasingKeyword} from './amp-fx-presets-utils'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New compared to #14276
@@ -33,5 +33,10 @@ | |||
<div> | |||
<h1 amp-fx="parallax"></h1> | |||
</div> | |||
<div amp-fx="fade-in"></div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New compared to #14276
@@ -34,5 +34,10 @@ PASS | |||
| <div> | |||
| <h1 amp-fx="parallax"></h1> | |||
| </div> | |||
| <div amp-fx="fade-in"></div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New compared to #14276
@@ -79,6 +79,38 @@ In this example, as the user scrolls the page, the h1 element scrolls faster rel | |||
</h1> | |||
``` | |||
|
|||
### fade-in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New compared to #14276
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for updating the docs in the same PR!
I would add a note about fade-in being experimental.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -288,6 +288,12 @@ const EXPERIMENTS = [ | |||
spec: 'https://github.com/ampproject/amphtml/issues/9074', | |||
cleanupissue: 'https://github.com/ampproject/amphtml/issues/14263', | |||
}, | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New compared to #14276
@@ -4524,7 +4524,7 @@ attr_lists: { | |||
# https://www.ampproject.org/docs/reference/components/amp-fx-collection | |||
attrs: { | |||
name: "amp-fx" | |||
value_casei: "parallax" | |||
value_regex_casei: "(fade-in|parallax)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New compared to #14276
@alanorozco I have rebased on to the rewrite in #14276 so this should be much easier to read now. |
} | ||
|
||
// If above the threshold of trigger-position | ||
if (!fxElement.isMutateScheduled()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Short-circuit here.
- Maybe changing
getResources()
tomutateElement
directly can save you a couple of steps (setIsMutateScheduled()
,getElement()
). - Arrow func.
if (fxElement.isMutateScheduled()) {
return;
}
fxElement.mutate(() => {
// ...
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the short circuiting here. However FxElement
doesn't extend BaseElement
so I don't think the mutateElement will work here, will it?
@@ -110,6 +118,19 @@ export class FxElement { | |||
|
|||
/** @private {number} */ | |||
this.factor_ = parseFloat(element.getAttribute('data-parallax-factor')); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What worries me about this style is that the specific FX are being scattered in more than one place.
For generic properties, like easing
or duration
, data-duration
(without the preset name) should work fine. If they are to be invalid for certain presets, we can add validation rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I share your concern here. Made the change. We already have one preset specific attribute data-parallax-factor
but I am going to talk to Ali about renaming that. That is a discussion for another thread though.
@@ -79,6 +79,38 @@ In this example, as the user scrolls the page, the h1 element scrolls faster rel | |||
</h1> | |||
``` | |||
|
|||
### fade-in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for updating the docs in the same PR!
I would add a note about fade-in being experimental.
@@ -134,6 +128,10 @@ class AmpFxCollection { | |||
|
|||
// Validate that we support the requested fx types. | |||
fxTypes.forEach(fxType => { | |||
if (fxType == FxType.FADE_IN) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be moved to the preset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uploaded a new commit with the changes you asked for. PTAL?
@@ -79,6 +79,38 @@ In this example, as the user scrolls the page, the h1 element scrolls faster rel | |||
</h1> | |||
``` | |||
|
|||
### fade-in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -110,6 +118,19 @@ export class FxElement { | |||
|
|||
/** @private {number} */ | |||
this.factor_ = parseFloat(element.getAttribute('data-parallax-factor')); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I share your concern here. Made the change. We already have one preset specific attribute data-parallax-factor
but I am going to talk to Ali about renaming that. That is a discussion for another thread though.
@@ -134,6 +128,10 @@ class AmpFxCollection { | |||
|
|||
// Validate that we support the requested fx types. | |||
fxTypes.forEach(fxType => { | |||
if (fxType == FxType.FADE_IN) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
|
||
// If above the threshold of trigger-position | ||
if (!fxElement.isMutateScheduled()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the short circuiting here. However FxElement
doesn't extend BaseElement
so I don't think the mutateElement will work here, will it?
* WIP * Refactor parallax code to make it easier to add new presets * Force Travis checks * Travis fixes * Private -> protected * Add support for amp-fx='fade-in'. Write example and validator tests accordingly as well * Demos post UX review * Add 'real world' example that uses amp-fx='fade-in' * Commit worthy test * Add support for easing keywords * Only access private members through accessors * Only access private members through accessors * Remove demo files * Add accessor for resources. * Fix linter errors * Formatting FUNS * Fix markdown * Moar demos * Gate amp-fx='fade-in' experiment * Edits before push * markdown changes * Bring back demos * remove US demos * Respond to alanorozco@'s comments * Fix build failures * Fix missing support check * Travis fixes * Cleanups * Remove references to fade-in * Don't use private members outside class * OOPS
This PR fixes #14351 adds the following functionality:
amp-fx="fade-in"
which triggers a timed fade in animation