In this tutorial you are going to learn how to create very nice, yet very powerful Elementor expandable elements. It works for text editor elements, image elements, and even container elements.
It works really well with Elementor dynamic data.
See the demo here:
Features:
- Works with dynamic data
- Works for as many Elementor expandable elements as you need
- Individually set "read more" and "read less" messages of your choice
- Works with any element. Expand and collapse images too, or even whole containers!
Let's get started!
First, let's copy paste this code in your project
This is a premium tutorial. Purchase access to unlock the full tutorial.
27 Responses
Worked perfectly. Don't forget to remove the paddings at the top and bottom of the sp-expandable container, otherwise a part of the container will be displayed despite the defaultPreviewHeight = "0px" setting.
Thanks for the great feature 🙂
Hey Fabian!
Yes indeed, need to be careful with top and bottom padding here... otherwise the height won't be what you expect it to be!
Cheers!
Hi Maxime, thanks again for another great feature. How do I achieve the chevron icons that rotate when View More / View Less is clicked?
Hey Gideon!
I updated the code recently and this should now work again as expected!
Please import the updated code to your project.
Thanks Maxime! Appreciated!
Hi Maxime, I am upgrading from 'Amazing Elementor Show Hide Section Button' tutorial, as I have switched to containers that are nested.
The overwrite settings for the text thats displayed within each toggle button doesn't appear to be working for me however when set under Advanced > Attributes.
When I set the following in Advanced > Attributes for each button, only the text set within the code snippet appears?
data-expand-text|Custom Text Expand
data-collapse-text|Custom Text Collapse
Also not getting the rotate icon feature, as I had working before with the previous tutorial.
Are you able to verify these are working? Thanks!
Hey James,
Could you share with me the URL of the page where you are testing this? I will have a look what's going on!
Cheers
Hi Maxime,
Thanks for your reply - the updated code now works great! Thanks again!
James
Awesome James, glad it works now!
Hi Maxime
Is it possible to make it work with a section or column?
Regards
Stefan
Hey Stefan!
I think it should be working for these already. Columns might be a bit buggy though... Sections should work.
Have you tried? If you have tried and have issues, please share your page with me I will check.
Thanks for the code. Is it possible to change the transparency value that appears on the button and the hidden content? And eliminate it altogether?
Hi Simone,
changing the value of "black 70px" to 0px inside <style> in all instances of the code did it for me. I'm pretty sure there is a cleaner way to do this though.
Kind regards.
Hi Maxime,
great tutorials as always. This would be awesome for my project, I even added a bit of code that removes the button after expanding (collapsing and scrolling to top was a bit pointless to my project).
However I had to remove everything because it has a glitch that happened by accident, but once you see it, you cannot unsee it. On mobile (tested with chrome, firefox and opera), if you scroll up and down (just enought for the browser adress bar to hide/show) the content will snap upwards / downwards, sometimes even skipping whole sections, sometimes skipping everything to the footer or header.
I thought maybe I had some other code conflicting, so I tested on your own template (https://templates.element.how/elementor-premium-expand-collapse-toggle-template/) and it happens too.
My theory is that this is related to the hide/ show of the adress bar of the browser app.
Kind regards.
@ Edit: removing this part of the code fixed the snapping for me:
window.addEventListener('resize',function(){
e.style.removeProperty('height');
expandedHeight = e.offsetHeight + "px";
if (!toggled){
e.style.height = height;
} else {
e.style.height = expandedHeight;
}
})
plus adding
expandToggle.style.display = 'none'; /*after expandToggle.classList.add('expanded-text');*/
to remove the button after expanding, made it tip top perfect. Now I just need to clean up parts of the code that i'm not using without breaking it 😀
Thanks Joao for making me aware of this!
I updated the resize code to ignore the URL bar on mobile.
Cheers!
Hi Maxime,
can you stack the expander?
I would like to depict the following scenario:
1. Inner container consisting of several box elements, each with a read more button (works great with your code!)
2. External container that I want to use to display the top row of boxes and hide the boxes underneath. By clicking on Read more, the inner container opens.
If I give the parent container the 'sp-expandable' class according to the same scheme, it works, but ONLY if the Read more button in the navigator is located hierarchically above the inner container. However, I would like to place this underneath.
Cheers
Chris
Greetings Christopher!
Do you have by any chance a link to the page where you are testing this?
That would help me understand better what's needed here to make it work!
Cheers!
Hi Maxime,
this code worked great for me in the past. But all of a sudden the functionality is reversed on one of my pages. https://photosteinmaurer.com/home-en/#publications
So when I click on show more it contracts instead of the opposite. Why is that?
Thanks a lot for your support!
Joachim
Greetings Joachim!
Ignore my other answer you might have received by email.
I updated the JavaScript in the tutorial, please import the code from the tutorial again and let me know if that fixes it.
Cheers!
It works! You are the best, thank you! 🤗❤️
Hi, it works but i have problem with the overflow and scroll. If the fields are not visible, the length of the page is not correct after the footer. It also hangs when scrolling. Can you help pls?
https://am-berlinbau.de/
Hey Engin!
Somewhere on your page you have this CSS:
html, body {
overflow-x: hidden;
}
directly below it, add this:
Cheers!
Thank you for Support
Work fine, perfect !
Thanks for this great feature 🙂
Work fine on CTP template page
BUT a little bug on TAXONOMIE template page.
the text is well hidden by the given CSS code and is displayed if the button is clicked. However the page seems to save the height of the page, so if you don't click on the "read more" button the hidden space is transferred under the footer.
exemple : https://nosybe-location.com/categories_produit/arts-de-la-table/ (just scrool bottom, you will see)
How to fix this problem please?
Greetings Antonin!
Please simply set the container overflow to hidden. The parent container, that has a <section> tag.
Cheers!