On my site, I have a container that holds multiple 'pages' of information. When a button is clicked, the current content page disappears and the next one appears on screen, allowing viewers to cycle through different windows of content on the same webpage. The buttons work perfectly, but I'm not having success with animating it. I want the text of the current page to move to the left and fade out while the next page fades in from the right. Here is what I have so far.
function fadeOutShowNext(currentId, nextId){
const currentSection = document.getElementById(currentId);
const nextSection = document.getElementById(nextId);
currentSection.classList.add('fade-out');
setTimeout(() => {
currentSection.style.display = 'none';
nextSection.style.display = 'block';
nextSection.classList.remove('fade-out');
}, 1000);
}
currentId and nextId are passed through from the button clicks. No problems there. Here is my fade-out class from my CSS:
.fade-out {
opacity: 0;
transition: opacity 1s ease-in-out;
}
As of right now, the text fades out like it should. However, if I try to add a similar fade-in class, it causes the fade-out effect to stop working. I've tried using ChatGPT for but it is not being any help at all. I'm not sure what I'm doing wrong. Everything in the current code makes sense to me but when trying to replicate the logic to add the additional effects, the fade-out animation just stops working. I would appreciate any assistance.