-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
base: main
Are you sure you want to change the base?
Changes from 19 commits
ec1fb62
d50d814
92dbfca
9fb3ac1
cac45e9
de2d5cd
4880e8f
3d1bbb2
82368fc
30469e4
514e3f0
ea6ad7f
0c1b406
9f16c7e
79f9c7a
df33e7b
142a2c3
2775766
269d577
9e3bad3
ebc1032
8fcc99a
3c11a40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const SCROLL_TRIGGER_CLASSNAME = "scroll-trigger"; | ||
const IN_VIEW_CLASSNAME = "scrolled-into-view"; | ||
|
||
const OPTIONS = { | ||
threshold: 0.5, | ||
}; | ||
|
||
function onIntersection(entries, observer) { | ||
for (const entry of entries) { | ||
if (entry.isIntersecting) { | ||
entry.target.classList.add(IN_VIEW_CLASSNAME); | ||
observer.unobserve(entry.target); | ||
} | ||
} | ||
} | ||
|
||
function initializeScrollTrigger() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Were you able to validate whether we should also be observing new elements as they are inserted by the Online Store Editor? As previously suggested, you can listen to the shopify:section:load event in the theme editor to observe newly added sections that weren't there when the code executed for the first time: document.addEventListener('shopify:section:load', (event) => {
intersectionObserver.observe(target);
}); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call - we have a separate ticket to add this observer and I included it as a requirement: #2316 There's a script in Dawn called "theme-editor.js" that gets loaded in the editor, so we'll probably put it in there. |
||
const scrollTriggerElements = Array.from( | ||
document.getElementsByClassName(SCROLL_TRIGGER_CLASSNAME) | ||
); | ||
|
||
if (scrollTriggerElements.length === 0) { | ||
return; | ||
} | ||
|
||
const observer = new IntersectionObserver(onIntersection, OPTIONS); | ||
|
||
scrollTriggerElements.forEach((element) => observer.observe(element)); | ||
} | ||
|
||
window.addEventListener("load", initializeScrollTrigger); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it common for us to wait for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this - my thinking is that we should wait for images to load before adding the listeners, but I didn't test too thoroughly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While working on the editor, we've seen a number of edge-cases where the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @metamoni |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2993,3 +2993,134 @@ details-disclosure > details { | |
outline: transparent solid 1px; | ||
} | ||
} | ||
|
||
/* Animations */ | ||
|
||
.scroll-trigger { | ||
transition: opacity 0.55s ease-in-out; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can experiment with the |
||
opacity: 0; | ||
} | ||
|
||
.scrolled-into-view { | ||
animation: 0.55s ease-in-out slideIn forwards; | ||
} | ||
|
||
.grid__item:nth-child(2n).scrolled-into-view, | ||
.grid__item:nth-child(2n) .scrolled-into-view, | ||
.collage__item:nth-child(2n) .scrolled-into-view { | ||
animation-delay: 0.1s; | ||
} | ||
|
||
@media screen and (min-width: 990px) { | ||
.grid--3-col-desktop .grid__item:nth-child(3n + 1).scrolled-into-view, | ||
.grid--3-col-desktop .grid__item:nth-child(3n + 1) .scrolled-into-view, | ||
.grid--3-col-desktop .collage__item:nth-child(3n + 1) .scrolled-into-view { | ||
animation-delay: 0.1s; | ||
} | ||
|
||
.grid--3-col-desktop .grid__item:nth-child(3n + 2).scrolled-into-view, | ||
.grid--3-col-desktop .grid__item:nth-child(n + 2) .scrolled-into-view, | ||
.grid--3-col-desktop .collage__item:nth-child(3n + 2) .scrolled-into-view { | ||
animation-delay: 0.2s; | ||
} | ||
|
||
.grid--3-col-desktop .grid__item:nth-child(3n + 3).scrolled-into-view, | ||
.grid--3-col-desktop .grid__item:nth-child(3n + 3) .scrolled-into-view, | ||
.grid--3-col-desktop .collage__item:nth-child(3n + 3) .scrolled-into-view { | ||
animation-delay: 0.3s; | ||
} | ||
|
||
.grid--4-col-desktop .grid__item:nth-child(4n + 1).scrolled-into-view, | ||
.grid--4-col-desktop .grid__item:nth-child(4n + 1) .scrolled-into-view { | ||
animation-delay: 0.1s; | ||
} | ||
|
||
.grid--4-col-desktop .grid__item:nth-child(4n + 2).scrolled-into-view, | ||
.grid--4-col-desktop .grid__item:nth-child(4n + 2) .scrolled-into-view { | ||
animation-delay: 0.2s; | ||
} | ||
|
||
.grid--4-col-desktop .grid__item:nth-child(4n + 3).scrolled-into-view, | ||
.grid--4-col-desktop .grid__item:nth-child(4n + 3) .scrolled-into-view { | ||
animation-delay: 0.3s; | ||
} | ||
|
||
.grid--4-col-desktop .grid__item:nth-child(4n + 4).scrolled-into-view, | ||
.grid--4-col-desktop .grid__item:nth-child(4n + 4) .scrolled-into-view { | ||
animation-delay: 0.4s; | ||
} | ||
|
||
.grid--5-col-desktop .grid__item:nth-child(5n + 1).scrolled-into-view, | ||
.grid--5-col-desktop .grid__item:nth-child(4n + 1) .scrolled-into-view { | ||
animation-delay: 0.1s; | ||
} | ||
|
||
.grid--5-col-desktop .grid__item:nth-child(5n + 2).scrolled-into-view, | ||
.grid--5-col-desktop .grid__item:nth-child(5n + 2) .scrolled-into-view { | ||
animation-delay: 0.2s; | ||
} | ||
|
||
.grid--5-col-desktop .grid__item:nth-child(5n + 3).scrolled-into-view, | ||
.grid--5-col-desktop .grid__item:nth-child(5n + 3) .scrolled-into-view { | ||
animation-delay: 0.3s; | ||
} | ||
|
||
.grid--5-col-desktop .grid__item:nth-child(5n + 4).scrolled-into-view, | ||
.grid--5-col-desktop .grid__item:nth-child(5n + 4) .scrolled-into-view { | ||
animation-delay: 0.4s; | ||
} | ||
|
||
.grid--5-col-desktop .grid__item:nth-child(5n + 5).scrolled-into-view, | ||
.grid--5-col-desktop .grid__item:nth-child(5n + 5) .scrolled-into-view { | ||
animation-delay: 0.5s; | ||
} | ||
} | ||
|
||
@keyframes slideIn { | ||
from { | ||
transform: translateY(10vh); | ||
opacity: 0; | ||
} | ||
to { | ||
transform: translateY(0); | ||
opacity: 1; | ||
} | ||
} | ||
|
||
/* Section-specific motion behavior. */ | ||
|
||
.banner__media.scroll-trigger { | ||
transition: opacity var(--duration-long) ease-in-out; | ||
opacity: 0; | ||
} | ||
|
||
.banner__media.scrolled-into-view { | ||
animation: none; | ||
opacity: 1; | ||
} | ||
|
||
.slideshow__slide:not(:first-of-type) .banner__media.scroll-trigger { | ||
opacity: 1; | ||
} | ||
|
||
/* Async loading prevents animation for Related Product cards. */ | ||
.related-products .grid__item .scroll-trigger { | ||
opacity: 1; | ||
animation: none; | ||
} | ||
|
||
/* Turn off animations if JS is turned off. */ | ||
.no-js .scroll-trigger, | ||
.no-js .scrolled-into-view { | ||
opacity: 1; | ||
animation: none; | ||
} | ||
|
||
/* Respect the visitor's motion preferences. */ | ||
@media (prefers-reduced-motion) { | ||
.scroll-trigger, | ||
.scrolled-into-view { | ||
opacity: 1; | ||
animation: none; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,6 +257,14 @@ | |
} | ||
} | ||
}, | ||
"motion": { | ||
"name": "Motion", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
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": { | ||
|
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.
spaces vs tabs? 😅
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 comment applies throughout the whole file, not just here 😅
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.
😅 Ha, whoops. Should be better now.