How to add animation to collapsible content on mobile

How to add animation to collapsible content on mobile

CreatorTim
Explorer
241 1 45

Hey guys, I want to add an animation for expanding the answers in the collapsible content section.

 

I’ve already added an animation using this code, but it only works on desktop:

.accordion details::details-content {
display: block;
margin-inline: 2rem;
block-size: 0;
overflow: hidden;
transition-property: block-size, content-visibility;
transition-duration: 0.3s;
transition-behavior: allow-discrete;
transition-timing-function: ease-out;
}
 
.accordion details[open]::details-content {
block-size: auto;
block-size: calc-size(auto, size);
}

 

So I’d like to add a similar or even the same animation, but make it work on MOBILE.

 

Here’s the store where it works on mobile, and I’d like a similar animation: https://tomnoske.store/products/cinema-luts (Just scroll down, there’s the collapsible content)

 

And here’s the link to my store: https://1049xn-ya.myshopify.com/products/editing-masterclass
(Just scroll down, there’s the collapsible content)

 

I ONLY NEED THIS ON MOBILE; IT WORKS ON DESKTOP!

 

Thanks so much,
Tim

Replies 5 (5)

Dan-From-Ryviu
Shopify Partner
10712 2120 2238

Hi @CreatorTim 

I see it working the same with example site. 

- Helpful? Like and Accept solution! Or Support me: Buy Me Coffee ❤️
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.

CreatorTim
Explorer
241 1 45

Hey, so when I tested it in the Shopify editor's mobile view, it worked fine. But when I opened the store on an actual mobile device, it didn’t work.

codingHelp1
Visitor
3 0 0

To add animation you can use following CSS code to fix it

/* Default styles for collapsible content */
.accordion details::details-content {
  display: block;
  margin-inline: 2rem;
  block-size: 0;
  overflow: hidden;
  transition-property: block-size, content-visibility;
  transition-duration: 0.3s;
  transition-timing-function: ease-out;
}

/* Expanded state */
.accordion details[open]::details-content {
  block-size: auto;
}

/* Mobile-specific styles */
@media (max-width: 768px) {
  .accordion details::details-content {
    display: block;
    margin-inline: 1rem; /* Adjust spacing for mobile */
    block-size: 0;
    overflow: hidden;
    transition-property: max-height, padding;
    transition-duration: 0.4s;
    transition-timing-function: ease-in-out;
  }

  .accordion details[open]::details-content {
    max-height: 300px; /* You can adjust this value based on the content size */
    padding: 10px; /* Add padding for smoother animation */
  }
}
Chat on WhatsApp: +923246370042
Need a Shopify developer? Hire us at noumanmasood64@gmail.com
For Shopify Design Changes | Shopify Custom Coding | Custom Modifications
CreatorTim
Explorer
241 1 45

Hey, your code isn’t working. It made it stop working not only on mobile but also on desktop.

codingHelp1
Visitor
3 0 0

Need to check code of theme then to fix it

Chat on WhatsApp: +923246370042
Need a Shopify developer? Hire us at noumanmasood64@gmail.com
For Shopify Design Changes | Shopify Custom Coding | Custom Modifications