When you exit container1 you add a class of bg1 to the body and that was the trigger to show container2 and hide container1.
Now when you exit container1 you actually show container2 and container3 at the same time. They are absolutely placed so they sit on top of each other.
You would need to put in some logic for multiple containers (which you have removed with your current demos). You would again need to use the hide class and place it on all the main containers except for the current one you want. You already had something like this before you removed all the code for it
Or you could probably add a class of bg2 to the body when you exit container2 and use that to hide container2 and show container3 (as you have done with bg1 for container1).
As I said above in the initial demo the bg1 was only used to change the body background. It was not a trigger for hiding and showing the other containers. This was done by adding the hide class as shown in this screenshot.
The ‘hide’ class was used to hide all the other containers except the one that was showing.
In the other demo also note that all the stripy backgrounds are on the container elements and the code first fades the body background color and then fades in the current container color. You then have some code that does the reverse and fades out the body and container and once all animations are finished removes the bg1 is removed from the body and all the play buttons are once again shown by removing the hide class and results in hiding everything except the play buttons.
Your current demo has little symmetry with that old code so I suggest you start again with your new methods in mind rather than to keep harping back to something that doesn’t do anything close to what you are asking now.
I already detailed what you should be looking at and that would be to add a new class to show the new container and hide the old containers.
Based on the class on the body triggering the showing and hiding of things you would need to have css like this.
However you would need to update the JS to add the bg1 class to the body which with your current code is too awkward for me as it just looks like spaghetti now.
For example You call resetPage function at the end of the first block here but all that does is call resetBackgroundBody function. What’s the point of that?
function animationEndHandler(evt) {
const animationName = evt.animationName;
console.log(animationName);
if (animationName === "initial-fade") {
body.classList.remove("initial-fade");
resetPage();
}
}
function resetPage() {
resetBackground("body");
}
I can’t understand the flow of the JS anymore. It was all built for some other functions.
Also if you are going t be adding container 4 and container 5 then you need to go back to looping through the containers rather than setting individually so the js and css also needs to change again.
I was just told this, if you’re able to understand it.
There’s a couple of different ways to fix the issues with this, so I’ll mainly point out what the problems are, and show you 1 way to accomplish what you are looking for.
Looking at your css it seems like the class .bg2 is what you want to display the div with the class .container3.
Your css:
.bg2 .container3 {
display: flex;
}
Now you need css to hide the div’s with the classes .container1, and .container2 when that .bg2 class gets applied.
Now the JS Your js that adds the class of .bg1 only gets ran once when the js is initialized. That’s why your class of .bg2 is not getting added. If you want to continue to solve the problem via this path, I would suggest moving the call to resetPage() (which is currently in the animationEndHandler() function), to the exitClickHandler() function. That way it will get called every time the exit button is clicked.
function animationEndHandler(evt) {
const animationName = evt.animationName;
console.log(animationName);
if (animationName === "initial-fade") {
body.classList.remove("initial-fade");
// moving this to exitClickHandler()
// resetPage();
}
}
function exitClickHandler() {
body.classList.add('initial-fade');
resetPage();
}
There’s one more change to make. I did this a quick way because I’m not sure how you’d like to handle the displaying of your containers.
In the resetBackground() function I stated above it’s only adding the class of bg1 to your body tag. We need to modify this because in your css you have a class of bg2 which hides the other 2 containers and shows the third container. I created a counter variable and set it to 1 because your first class to add is bg1. Then I increment the counter after bg1 is added to your body tag. So next time the class added to your body tag is bg2.
let counter = 1;
function resetBackground(backgroundSelector) {
const background = document.querySelector(backgroundSelector);
background.classList.add("bg" + counter);
counter++;
}
Again, there’s multiple ways to accomplish the hiding and displaying of your containers of videos. Hope this helps you.
You are adding bg1 and initial-fade and then removing both when the animation has ended. I think you could do it with just the one animation.
What happens when you go to the third container as the body background is now already teal. There is no background change as there was with the first.
The container logic is also flawed and I think you need to go back to using .hide and finding the parent from the parent of the button that was pressed.
This following example gets the containers showing when you click the exit button. I made it go back to the first container when the exit button on the first container was clicked.
The above was only concerned with the correct containers showing and I have not addressed any issues that would be broken by doing this. The fades are all wrong.
I wouldn’t use any of that code yet as I haven’t had time today to sort it out but it does show how the containers can be shown. I’ll be back tomorrow and have a deeper look.
I also reduced the CSS as you had about 150 lines of code instead of 15. The video-one to video-eleven css was exactly the same sand duplicated multiple times so I changed it to just this.