I have a website that uses buttons to show/hide additional elements. If the user clicks through all the buttons the amount of extra content on screen adds up, so I’d like to include a ‘collapse all’ button in the bottom right that pops up and allows the user to quickly reset the buttons on the page. Ideally this ‘collapse all’ button will appear only when one of these buttons are clicked, and then the user can choose to click it to close any elements that have been triggered to open. Once all the buttons are closed again the ‘collapse all’ button should also be hidden.
I’ve tried piecing together code from an assortment of tutorials but it didn’t make a 100% sense to me since I couldn’t find the exact concept I’m looking for . Most of my attempts involved going through the different animations in the sitejet builder and playing around with the group/trigger options but I couldn’t figure out the solution.
Ahh! Thank you so much for this, and for providing the helpful instructions too. It sounds like exactly the solution I needed, I’ll definitely try this out and let you know how I go!
$(function() {
const $container = $('.myContainer');
const $toggleButton = $('.myToggleButton');
function showToggleButton() {
$toggleButton.show();
}
function hideContent() {
$('.myContent', $container).hide();
$('.ed-button a.button', $container).removeClass('active'); //reset the buttons on the page
$toggleButton.hide(); // hide toggleButton when resetting all buttons
}
$container.on('click', '.ed-button a.button', showToggleButton); // show me the toggleButton, when one of these buttons are clicked
$toggleButton.on('click', hideContent);
});