-
Notifications
You must be signed in to change notification settings - Fork 918
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
Update hero with flag animation (fixes #15515 and #15597) #15525
Changes from all commits
e7f78a7
777e48d
87af091
b043a3d
48980cd
3820b30
4e20349
7210c34
78d41fe
f7ef8a3
1f0ba0a
cf081a0
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 |
---|---|---|
|
@@ -20,6 +20,8 @@ ui-show-all = Show All | |
ui-hide-all = Hide All | ||
ui-learn-more = Learn more | ||
ui-view = View | ||
ui-pause-animation = Pause animation | ||
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. Praise: Thanks for making these global. |
||
ui-play-animation = Play animation | ||
|
||
# An accessible label used to describe the purpose of a cross-promotional page element. | ||
ui-promo-label = Promotion |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
.m24-c-flag { | ||
@include container; | ||
padding-top: $spacer-2xl; | ||
padding-top: $spacer-xl; | ||
padding-bottom: $spacer-xl; | ||
} | ||
|
||
|
@@ -25,12 +25,79 @@ | |
margin-bottom: $spacer-xl; | ||
} | ||
|
||
.m24-c-flag-cta { | ||
margin-bottom: 0; | ||
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. removes default p spacing |
||
} | ||
|
||
.m24-c-flag-media { | ||
display: block; | ||
margin-bottom: 16px; | ||
--delay: 1s; // leave some space to read before introducing movement | ||
--wave-h: 8px; | ||
|
||
img { | ||
svg { | ||
transform: translateZ(0); | ||
width: 100px; | ||
height: auto; | ||
fill: $m24-color-green; // zilla green | ||
} | ||
} | ||
|
||
.m24-c-flag-button { | ||
$font-size: 0.75; | ||
background-color: $m24-color-dark-mid-gray; | ||
border: none; | ||
box-shadow: none; | ||
color: $m24-color-white; | ||
font-family: $primary-font; | ||
font-size: calc(#{$font-size} * 1rem); | ||
font-weight: 600; | ||
line-height: $font-size; | ||
padding: 8px; | ||
cursor: pointer; | ||
transition: background-color $fast; | ||
|
||
&:hover, | ||
&:focus { | ||
background-color: $m24-color-black; // inverts to white in dark theme section | ||
} | ||
|
||
&:active { | ||
background-color: $m24-color-dark-mid-gray; | ||
} | ||
} | ||
|
||
.m24-c-flag-button-pause, | ||
.m24-c-flag-button-play { | ||
align-items: center; | ||
display: flex; | ||
gap: 8px; | ||
} | ||
|
||
.m24-c-flag-button-pause { | ||
.m24-c-flag-button-text { | ||
position: relative; | ||
top: 0.0175rem; // flex alignment isn't totally centered, so we're manually adjusting | ||
} | ||
} | ||
|
||
@media screen and (max-width: #{$screen-lg - 1}) { | ||
.m24-c-flag-cta { | ||
margin-bottom: $spacer-xl; | ||
} | ||
|
||
.m24-c-flag-button { | ||
border-radius: 50%; | ||
display: block; | ||
margin-bottom: $spacer-md; | ||
margin-inline-start: auto; | ||
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. logical properties have pretty good support now, so I decided to use them as enhancement here instead of bidi mixin |
||
} | ||
|
||
.m24-c-flag-button-text { | ||
@include visually-hidden; | ||
} | ||
|
||
.m24-c-flag-media { | ||
width: fit-content; | ||
margin-inline-start: auto; | ||
} | ||
} | ||
|
||
|
@@ -44,29 +111,36 @@ | |
@media #{$mq-lg} { | ||
.m24-c-flag { | ||
@include grid; | ||
grid-template-rows: [button-row-start] auto [button-row-end] auto; | ||
padding-bottom: $spacer-2xl; | ||
} | ||
|
||
.m24-c-flag-button { | ||
grid-column: 1 / -1; | ||
grid-row: button-row; | ||
justify-self: end; | ||
} | ||
|
||
.m24-c-flag-subtitle { | ||
font-size: 24px; | ||
} | ||
|
||
.m24-c-flag-media { | ||
grid-column: 10/12; | ||
grid-row: 1/2; | ||
grid-row-start: button-row-end; | ||
display: flex; | ||
place-content: center center; | ||
margin-bottom: 0; | ||
|
||
img { | ||
svg { | ||
width: 100%; | ||
max-width: 216px; | ||
} | ||
} | ||
|
||
.m24-c-flag-text { | ||
grid-column: 2/9; | ||
grid-row: 1/2 | ||
grid-row-start: button-row-end; | ||
} | ||
|
||
.m24-c-flag-cta { | ||
|
@@ -86,3 +160,143 @@ | |
.m24-c-products { | ||
background-color: $m24-color-white; | ||
} | ||
|
||
// static fallback | ||
.m24-c-flag-media-static { | ||
display: none; | ||
} | ||
|
||
// When no JS or M24_HERO_ANIMATION switch is off | ||
// - hide animation SVG and button | ||
// - show static SVG | ||
.no-js, | ||
[data-m24-hero-animation="false"] { | ||
.m24-c-flag-button { | ||
visibility: hidden; // reserve space | ||
} | ||
|
||
.m24-c-flag-media-animation { | ||
display: none; | ||
} | ||
|
||
.m24-c-flag-media-static { | ||
display: block; | ||
} | ||
} | ||
|
||
/* | ||
Note from Inclusive Components, "Changing labels": https://inclusive-components.design/toggle-button/ | ||
As a rule of thumb, you should never change pressed state and label together. | ||
If the label changes, the button has already changed state in a sense, | ||
just not via explicit WAI-ARIA state management. | ||
*/ | ||
[data-animation-running="false"] { | ||
.m24-c-flag-button-pause { | ||
display: none; | ||
} | ||
|
||
.flag-one, | ||
.flag-two, | ||
.flag-three, | ||
.flag-four, | ||
.flag-five { | ||
animation-play-state: paused; | ||
} | ||
} | ||
|
||
[data-animation-running="true"] { | ||
.m24-c-flag-button-play { | ||
display: none; | ||
} | ||
|
||
.flag-one, | ||
.flag-two, | ||
.flag-three, | ||
.flag-four, | ||
.flag-five { | ||
animation-play-state: running; | ||
} | ||
} | ||
|
||
/* Common Element Styles */ | ||
.flag, | ||
.flag-one, | ||
.flag-two, | ||
.flag-three, | ||
.flag-four, | ||
.flag-five, | ||
.pole, | ||
.head, | ||
.pole-one, | ||
.pole-two, | ||
.eye, | ||
.mouth { | ||
shape-rendering: crispEdges; | ||
-webkit-font-smoothing: none; | ||
-moz-osx-font-smoothing: none; | ||
} | ||
|
||
/* Wave Animations Base */ | ||
.flag-one, | ||
.flag-two, | ||
.flag-three, | ||
.flag-four, | ||
.flag-five { | ||
animation: 1s var(--delay) $bezier infinite; | ||
will-change: transform; | ||
filter: url("#dilate"); | ||
} | ||
|
||
/* Flag Animation Names */ | ||
.flag-one { animation-name: flag-one; } | ||
.flag-two { animation-name: flag-two; } | ||
.flag-three { animation-name: flag-three; } | ||
.flag-four { animation-name: flag-four; } | ||
.flag-five { animation-name: flag-five; } | ||
|
||
|
||
/* Flag Movement Keyframes */ | ||
@keyframes flag-one { | ||
0%, 15% { | ||
transform: translate3d(0, 0, 0); | ||
animation-timing-function: ease-in; | ||
} | ||
16%, 40% { transform: translate3d(0, var(--wave-h), 0); } | ||
41%, 65% { transform: translate3d(0, 0, 0); } | ||
66%, 91% { transform: translate3d(0, calc(-1 * var(--wave-h)), 0); } | ||
92%, 100% { transform: translate3d(0, 0, 0); } | ||
} | ||
|
||
@keyframes flag-two { | ||
0%, 24% { transform: translate3d(0, 0, 0); } | ||
25%, 49% { transform: translate3d(0, var(--wave-h), 0); } | ||
50%, 74% { transform: translate3d(0, 0, 0); } | ||
75%, 99% { transform: translate3d(0, calc(-1 * var(--wave-h)), 0); } | ||
100% { transform: translate3d(0, 0, 0); } | ||
} | ||
|
||
@keyframes flag-three { | ||
0%, 7% { transform: translate3d(0, calc(-1 * var(--wave-h)), 0); } | ||
8%, 32% { transform: translate3d(0, 0, 0); } | ||
33%, 57% { transform: translate3d(0, var(--wave-h), 0); } | ||
58%, 82% { transform: translate3d(0, 0, 0); } | ||
83%, 100% { transform: translate3d(0, calc(-1 * var(--wave-h)), 0); } | ||
} | ||
|
||
@keyframes flag-four { | ||
0%, 15% { transform: translate3d(0, calc(-1 * var(--wave-h)), 0); } | ||
16%, 49% { transform: translate3d(0, 0, 0); } | ||
50%, 65% { transform: translate3d(0, var(--wave-h), 0); } | ||
66%, 100% { transform: translate3d(0, 0, 0); } | ||
} | ||
|
||
@keyframes flag-five { | ||
0%, 24% { transform: translate3d(0, calc(-1 * var(--wave-h)), 0); } | ||
25%, 49% { transform: translate3d(0, 0, 0); } | ||
50%, 74% { transform: translate3d(0, var(--wave-h), 0); } | ||
|
||
75%, 100% { | ||
transform: translate3d(0, 0, 0); | ||
animation-timing-function: ease-out; | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
const ANIMATION_RUNNING = 'data-animation-running'; | ||
|
||
function togglePlayState(e) { | ||
const animationContainer = e.target.closest(`[${ANIMATION_RUNNING}]`); | ||
if (animationContainer.getAttribute(ANIMATION_RUNNING) === 'true') { | ||
animationContainer.setAttribute(ANIMATION_RUNNING, 'false'); | ||
} else { | ||
animationContainer.setAttribute(ANIMATION_RUNNING, 'true'); | ||
} | ||
} | ||
|
||
function init() { | ||
// play animations if motion is allowed | ||
if (window.Mozilla.Utils.allowsMotion()) { | ||
const animationContainers = document.querySelectorAll( | ||
`[${ANIMATION_RUNNING}]` | ||
); | ||
animationContainers.forEach((container) => | ||
container.setAttribute(ANIMATION_RUNNING, 'true') | ||
); | ||
} | ||
|
||
// play or pause animations on button click | ||
const playStateButtons = document.querySelectorAll('.js-animation-button'); | ||
playStateButtons.forEach((button) => | ||
button.addEventListener('click', (e) => togglePlayState(e)) | ||
); | ||
} | ||
|
||
init(); |
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.
went for assertive here as the text change might be confusing if not announced immediately after button click