Skip to content
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

Try adding global scroll animations to Dawn #2141

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions assets/animations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function() {
// Add animation classes.
function onIntersection(entries) {
for (const entry of entries) {
entry.target.classList.add('animate');
if (entry.isIntersecting) {
entry.target.classList.add('animate--active');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an intersection observer to add a class to animated elements seems like a good approach to me 👍

I think in the final implementation we will want to separate the concerns a bit more. Instead of adding an animate class here we will add a scrolled-into-view class, and elsewhere (i.e. in the css for the elements themselves) we can decide how to interpret that.

}
}

const intersectionObserver = new IntersectionObserver(onIntersection, {
thresholds: [1],
});
const selector = '.section, .banner__box, .product__info-wrapper';
const elementsToObserve = Array.from(document.querySelectorAll(selector));

// Observe intersections between the viewport and the elements.
elementsToObserve.forEach((element) => intersectionObserver.observe(element));
})();
38 changes: 38 additions & 0 deletions assets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -2957,3 +2957,41 @@ details-disclosure > details {
outline: transparent solid 1px;
}
}

/* Animations */

.animate {
transition: opacity 0.55s ease-in-out;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can experiment with the cubic-bezier easing function instead of ease-in-out if you want more control. This web app is a neat tool I just found: https://cubic-bezier.com/#.17,.51,.31,1

opacity: 0;
}

.animate--active {
animation: 0.55s ease-in-out slideIn;
opacity: 1;
}

@keyframes slideIn {
from {
transform: translateY(10vh);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}

/* Omit the first section, since that'll be above by default */
#MainContent > .animate:first-child {
opacity: 1;
animation: none;
}

/* Respect the visitor's motion preferences. */
@media (prefers-reduced-motion) {
.animate,
.animate--active {
opacity: 1;
animation: none;
}
}
11 changes: 11 additions & 0 deletions config/settings_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,17 @@
}
]
},
{
"name": "t:settings_schema.motion.name",
"settings": [
{
"type": "checkbox",
"id": "motion_toggle",
"label": "t:settings_schema.motion.settings.motion_toggle.label",
"default": false
}
]
},
{
"name": "t:settings_schema.social-media.name",
"settings": [
Expand Down
4 changes: 4 additions & 0 deletions layout/theme.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,9 @@
{%- if settings.predictive_search_enabled -%}
<script src="{{ 'predictive-search.js' | asset_url }}" defer="defer"></script>
{%- endif -%}

{%- if settings.motion_toggle -%}
<script src="{{ 'animations.js' | asset_url }}" defer="defer"></script>
{%- endif -%}
</body>
</html>
8 changes: 8 additions & 0 deletions locales/en.default.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@
}
}
},
"motion": {
"name": "Motion",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localization quality issue found

The following issues may affect the quality of localized translations if they are not addressed:

  • The value Motion for key settings_schema.motion.name is very short. Short strings are more likely to be misunderstood by translators without context. Please provide additional context for the translators if possible.

Please look out for other instances of this issue in your PR and fix them as well if possible.

Questions about these messages? Hop in the #help-localization Slack channel.

"settings": {
"motion_toggle": {
"label": "Reveal sections on scroll"
}
}
},
"social-media": {
"name": "Social media",
"settings": {
Expand Down