-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Motion] No animation on added/edited section #2502
Conversation
This feels pretty good! @ludoboludo, how do you feel about the experience with these changes? I do sort of miss the initial slide-in of some above-the-fold elements, but maybe that's because I've been seeing them slide in for so long now. Let's all test this and let it sit for a few days before we merge in. |
After tweaking our animations which are feeling much nicer now, we agreed not to prevent them from happening for elements in the viewport on load. So this PR (description updated) is more about preventing the animation to happen when not necessary in the theme editor. |
Thanks for revising the PR, @ludoboludo! This feels pretty good. Is it possible to turn off all the animations during this zoomed-out reorder state? 12-37-lgsho-g0iuh.mp4 |
assets/animations.js
Outdated
document.addEventListener('shopify:section:load', (event) => initializeScrollAnimationTrigger(event.target)); | ||
if (Shopify.designMode) { | ||
document.addEventListener('shopify:section:load', (event) => initializeScrollAnimationTrigger(event, event.target)); | ||
document.addEventListener('shopify:section:reorder', (event) => |
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.
@kjellr I added something for the section being re ordered. One thing to note, when I checked, I can only prevent the animation on the section I'm currently trying to re order. Any other section has the animation re running.
When I checked, section:load
event wasn't triggered on other sections, so it must be a full page reload. I think it's ok though as long as the section we're currently moving around isn't animating every time we're moving it around.
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.
Hmm ok. I'd definitely prefer to have the other animations stop on reorder too. Can we add a body class with some !important
rules or something to disable all animations when you're in that mode or something? 😅
Either way, what we have here is an improvement, so happy to get this merged in and tackle improvements separately. I'll add an approval for now, with the caveat that if we come up with a quick fix to stop all animation on reorder, we should take it.
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.
Ok so I can actually do it by making it remove the animation from all present sections that usually do animate. One of the potential issue with this, is that if you're at the top of a page and you haven't fully scrolled down yet and triggered the animations and you're reordering one of your first section on the page, nothing will be animated on further navigation on this page until page reload.
Here is a video cause it's seem hard to explain without visual aid.
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.
Ah, nice work! This seems like a pretty good solution. From watching the video, I'm not concerned about the subsequent sections not animating. That seems like a reasonable tradeoff in this case. If you're happy with the dev solution, let's push it up here and test it out.
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.
This generally looks good. Add a few additional notes in #2502 (comment).
assets/animations.js
Outdated
document.addEventListener('shopify:section:load', (event) => initializeScrollAnimationTrigger(event.target)); | ||
if (Shopify.designMode) { | ||
document.addEventListener('shopify:section:load', (event) => initializeScrollAnimationTrigger(event, event.target)); | ||
document.addEventListener('shopify:section:reorder', (event) => initializeScrollAnimationTrigger(event)); |
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.
If you don't pass in an element to initializeScrollAnimationTrigger
it will create a new intersection observer for the entire document, which already has one from line 34. Can we just create the new observer for the section(s) that was reordered?
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 had it for the specific section in the first place but it worked in a way that only the re ordered section was not getting animated while every other section was (video).
What I did just now was adding an early return within my if statement. So that if the event triggering the initialization is coming from the editor ((re)load
or reorder
) so we're not observing more element as it's unnecessary since the classes applied prevent the animation from happening anyway.
assets/animations.js
Outdated
const animationTriggerElements = Array.from(rootEl.getElementsByClassName(SCROLL_ANIMATION_TRIGGER_CLASSNAME)); | ||
if (animationTriggerElements.length === 0) return; | ||
|
||
if (isDesignMode) { |
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.
Is isDesignMode
simply Shopify.designMode
or is there another use case where these won't be equal?
If they're the same thing, do we need this another variable/parameter instead of simply checking for Shopify.designMode
?
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 just changed the name based on your comment. It's not exactly Shopify.designMode
but theme editor triggered events
.
Cause for example you can be in the editor (Shopify.designMode = true) but we want to run some logic specifically for the section:load
and section:reorder
events.
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.
Looks good to me now :D
* [Motion] Use rootMargin instread of threshold to trigger slide in animations (#2517) * Use rootMargin instread of threshold to trigger slide in animations * address review comment, remove threshold * Add conditional around data-cascade attribute (#2532) * [Motion] No animation on added/edited section (#2502) --------- Co-authored-by: Ludo <ludo.segura@shopify.com>
PR Summary:
Prevent having animation while being in the editor.
Why are these changes introduced?
Fixes https://github.com/Shopify/themes/issues/400
What approach did you take?
I added some logic that only runs in the
DOMContentLoaded
listener,shopify:section:reorder
, andshopify:section:load
. So it should run when the page loads, when you're re ordering a section or when you're editing a section in the editor.It adds a new class that overwrite the other ones.
Other considerations
At first I was thinking of removing the existing classes we had but I though it was cleaner/clearer to have a specific class to prevent
fade in
andslide in
animations.Decision log
Do not apply animation on elements in the viewport on page loadVisual impact on existing themes
In the editor, prevent a section from being animated anytime it's re rendered due to setting changes.
Testing steps/scenarios
Demo links
Checklist