-
Anonymous
Hi there,
I love the new tabs and accordion in Generate press. I have one question. I want all items of the accordion open on desktop (using default settings) and closed on mobile. Is this possible? The current default setting is for all screen sizes.
Regards,
Martijn -
Hi there,
thanks for the kind words 🙂
Can i see what you have so far on your site ? It may be possible with a little extra JS.
-
Anonymous
Hi David, great. I’ve added login details for the website (that’s work in progress) below.
Regards,
Martijn -
David
You could try some JS to “click” on each accordion item after to load to open them all and only on larger screens:
<script> const accordionItems = document.querySelectorAll('.gb-accordion__item'); if (window.innerWidth >= 768) { accordionItems.forEach((item) => { const clickEvent = new MouseEvent('click', { view: window, bubbles: true, cancelable: true }); // Dispatch the click event on the accordion item element item.dispatchEvent(clickEvent); }); } </script>
-
Anonymous
Hi David,
Thanks. But I can’t get it to work properly. I’ve added the script to the page (template).
My accordion items are currently open by default on the desktop and I hide the accordion title on desktop.Am I missing something?
Kind regards,
Martijn -
David
Ooh.. I didn’t realise the entire page were accordions.
Ok, remove the script I provided.Then set all the items to be closed by default.
We can then use some CSS on desktop only to force them ALL to be open. -
Anonymous
Hi David.
No problem. Could you give me a hint on how to open them by CSS?
Regards,
Martijn -
David
Something like this:
@media(min-width: 769px) { .open-on-desktop .gb-accordion__content { max-height: inherit !important; } }
And select the Accordion Items Block and give it a class of:
open-on-desktop
If that don’t work, then close the accordions on desktop and let me know
-
Anonymous
Hi David.
Thank you very much.
All accordion items block settings disabled -item default open- and are now opened on desktop by default and closed on mobile, as intended. It works perfectly.
Excellent support, as always. I learned a lot. I did not know that opening and closing the accordion items could be solved even with CSS instead of javascript.
Sincerely,
Martijn -
David
Awesome
Glad to be of help 🙂
- You must be logged in to reply to this topic.