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

[Cards and Buttons] 3D "Lift" effect on hover #2452

Merged
merged 64 commits into from
Apr 26, 2023
Merged

[Cards and Buttons] 3D "Lift" effect on hover #2452

merged 64 commits into from
Apr 26, 2023

Conversation

kjellr
Copy link
Contributor

@kjellr kjellr commented Mar 20, 2023

PR Summary:

This PR adds an optional "3D Lift" to Cards and Buttons wherein the element appears to lift off the page on hover. The element also receives a subtle shine effect while it's lifted up off the page.

20-19-iun43-vh4a2.mp4

Why are these changes introduced?

Closes #2451.

What approach did you take?

The animations are just a couple CSS transitions:

  • The lift effect is achieved by adding a drop shadow and slight rotation on hover. The element does not actually get any larger, it just appears to due to the combination of the shadow + existing border and zoom transitions on these elements.
  • The shine is achieved by adding a pseudo element on top that includes a gradient background. On hover, this background changes its position and opacity.
  • These are all activated by a single global class that's conditionally applied the the body.

Other considerations

Since the effect is purely aesthetic, it becomes inactive when the visitor has prefers-reduced-motion active.

Known bugs:

  • Currently, buttons don't get the shine. I couldn't find a great place to add the necessary pseudo class to make this happen and didn't want to make things more complicated by adding more wrappers. I don't really mind not having the shine on buttons, but I'd love a second opinion.
  • The buy button sometimes shows an annoying flash when you hover out.
  • I'm currently targeting some very specific selectors, and some relatively generic ones. While testing, we should figure out exactly where this hover state should and should not go into effect.
  • It's possible to have the card move around and react to the mouse's position on it (like what happens on Apple TV). This would require adding some Javascript.

Visual impact on existing themes

This feature is optional, and off by default. When merchants activate it by selecting it from the dropdown in Theme Settings, buttons and product cards across their storefront will receive this new hover effect.

Testing steps/scenarios

  1. Visit the demo store's editor.
  2. Visit Theme Settings > Animations
  3. Select "3D Lift" from the "Hover Effect" dropdown.
  4. Hover over product cards and buttons, see the new hover effect.

Demo links

Checklist

@kjellr kjellr added Category: Enhancement New feature or request motion labels Mar 20, 2023
@kjellr kjellr self-assigned this Mar 20, 2023
assets/base.css Outdated Show resolved Hide resolved
The z-index change is required to make sure the hover shadow is visible when a button is inside of a container that has overflow:hidden set.
assets/base.css Outdated Show resolved Hide resolved
@kjellr
Copy link
Contributor Author

kjellr commented Apr 10, 2023

I pushed some changes to improve the way this works when cards have an existing dropshadow. Now it no longer replaces the dropshadow, but appears in addition. Since we're retaining the original shadow, this will work better for themes like Crave, which use a solid dropshadow around their cards.

Examples

Solid shadow example

shadows.mp4

Diffused shadow example

shadow-02.mp4

mix-blend-mode: color-dodge;
pointer-events: none;
z-index: 2;
}
Copy link
Contributor

@stufreen stufreen Apr 10, 2023

Choose a reason for hiding this comment

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

If you don't want to use the easter egg CSS variable you could also just add new CSS rules and the merchant can unlock them by editing the setting value with the text editor. This won't take them off the upgrade path. As far as I know we don't validate the setting values, so you could set it to something like sparkle in the text editor even if that's not an option in the online store editor.

Screen.Recording.2023-04-10.at.11.42.09.AM.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting! I think that could be a fun way to do it. My main hesitation is that the sparkles are currently in addition to the rest of the 3d lift rules — I'd need to add a lot of duplicate rules in to target both .animate--hover-3d-lift and .animate--sparkle. The selectors are already getting a little heavy, so I'm hesitant to duplicate them all.

@kjellr
Copy link
Contributor Author

kjellr commented Apr 10, 2023

Complementary product block; the last product card, the diffused shadow is cut off.

This one doesn't look like a straightforward fix. It's enough of a minor one that I think we can punt it to a followup PR.

Collage section; Style all as product cards setting it would be great if the hover effect could be applied when this setting is true.

I think in this case, the only one that doesn't have the hover effect is the image — I think that's fine because it's not clickable anyway. Let me know if I'm misinterpreting something though!


Coming back to my note up here, I pushed some changes to simplify the way I was targeting buttons. This should now cover (almost?) all of the buttons that should animate, without requiring all the :not() rules from previous iterations. Please give it another round of testing, and let me know how it's feeling!

@stufreen
Copy link
Contributor

Still looks good to me. I tested the Sparkles and seems to be working as expected.

@melissaperreault
Copy link
Contributor

melissaperreault commented Apr 21, 2023

For Collage, totally aligned!

I found just 2 outsiders only!

@kjellr
Copy link
Contributor Author

kjellr commented Apr 25, 2023

Great catch, @melissaperreault! Should be fixed now, and ready for another review!

Copy link
Contributor

@melissaperreault melissaperreault left a comment

Choose a reason for hiding this comment

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

Yeah! Everything looks good! Thank you for all the hard work! 🚢 🚢 🚢

@kjellr
Copy link
Contributor Author

kjellr commented Apr 26, 2023

🙌 Thank you all!

@kjellr kjellr merged commit 4ec672a into main Apr 26, 2023
@kjellr kjellr deleted the animation-3d-lift branch April 26, 2023 13:30
phapsidesGT pushed a commit to Gravytrain-UK/gt-shopify-dawn-theme that referenced this pull request Sep 3, 2024
* Initial commit.

* Remove (probably) unnecessary will -change.

* Rename form field label.

* Add comments, refine values.

* Void the effect if reduce motion is active.

* Remove unnecessary params for animation.

* Create smoother shine animation on mouse out.

* Update mix-blend-mode for shine.

* Smooth out the mouse-out animation for cards.

* Remove unnecessary rule.

* Use (hover: hover) media query

* Simplify selectors, add z-index update.

The z-index change is required to make sure the hover shadow is visible when a button is inside of a container that has overflow:hidden set.

* Make cards clickable.

* FIx shine animation.

* Prevent clicks with pointer-events: none.

* Ensure gradient edges don't show.

* Remove redundant specificity.

* Start the shine slightly sooner.

* Extend animations to cards with shapes.

* Fix transform animation speed.

* Remove browser prefix.

* Use duration variables.

* Change duration extended value.

* Use duration variable again.

* Less intense rotation for collage items.

* Remove animation from videos posters.

* Tidy up the animation on the video play button.

* Fine-tune the video play button animation.

* Remove unnecessary rotation transforms.

* Add sparkles.

* Update 14 translation files

* Update locales/en.default.schema.json

Co-authored-by: melissaperreault <[email protected]>

* Don't apply to link-text.

* Remove the animation from buttons that don't need it.

* Only target enabled buttons.

* Cover special cases where we don't want the button to appear.

* Tidy up sparkles.

* Update 5 translation files

* Update 1 translation file

* Don't target buttons that are links.

* Adjust sparkle tactic.

* Update behavior when shadows are present.

* Fix appearance for card shapes hovers..

* Fix more button special cases.

* Simplify button selectors.

* Remove broken dynamic payment button styles.

* Get the right selectors in place.

* Update 12 translation files

* Update 7 translation files

* Update 1 translation file

* Don't apply to tertiary buttons.

---------

Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>
Co-authored-by: melissaperreault <[email protected]>
Co-authored-by: Ludo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Cards and Buttons] 3D "Lift" effect on hover
6 participants