Currently, only the 1st button is able to work: https://jsfiddle.net/1o2nr8mx/
All the curtains open, just no video is showing.
I am trying to figure out how to get the other videos to appear.
One of the things you said I could do was remove .outer
from the html, how would that be done?
Assuming I am able to now.
I received an error when I tried to remove it.
Which points to this line in the coide:
container.classList.add("active");
What other changes would need to be made to the CSS also?
What was done to the code was this:
The problem here is inside the body of the function
showCover
, which adds the classactive
and calls the functionshow
(which removes the classhide
) to and from the parent of the button , instead of the.container
element where it should be. My solution will work if you’re sure the parent element of the button comes right after the parent element of the.container
element, because it usespreviousElementSibling
. Note that your code also makes it so that the button isn’t hidden when it’s clicked, because the CSS selector that makes it hidden is.container.active .cover
, which assumes the button is a child of.container
, which in this case it isn’t. So you should change that CSS selector to.playButtonContainer.active
(not including.cover
makes sure it hides the parent element of the button). I also addedwith-curtain
to the button’s classes, so that theshowCurtain
function would remove itsactive
class too.
/* when container is active hide the cssPlay and show the inner container*/
.playButtonContainer.active {
display: none;
}
<div class="playButtonContainer with-curtain">
<button class="playa cover" type="button"></button>
<button class="playb cover" type="button"></button>
<button class="playc cover" type="button"></button>
</div>
Before the updated code below was received:
function showCover(playButton) {
hideAll(config.containers);
resetPage();
markAsPlayed(playButton);
const cover = playButton.parentElement;
const container = cover.previousElementSibling.querySelector(".container");
cover.classList.add("active");
container.classList.add("active");
show(cover);
show(container);
}
Just received this:
You need to find a way to map buttons to containers.
That could be done by adding a
data-container
attribute to each button which stores a class or an id of the container it should act upon. If you did that, you’d need a different class or id for each container (you already do that withplay1
andplay2
). Add adata-container
attribute to each button with its value as the corresponding container class (like for example:data-container="play1"
to the.playa
button anddata-container="play2"
to the.playb
button) and replacecover.previousElementSibling.querySelector(".container")
withdocument.getElementsByClassName(playButton.dataset.container)[0]
.Another way to do it would be by getting the index of a button in an array of all of the children of its parent element and match the container with the same index, within its own parent element. You already do this with the
.wrap
element. This makes maintenance easier, but requires elements be organized in a much stricter way.First solution: https://jsfiddle.net/anehz6d7/ Second solution: https://jsfiddle.net/w6hx4j1r/
When I removed .outer
from those 2 solutions, the errors went away and the curtain opened.
After the curtains closed, the buttons did not come back.
First Solution:
<div class="playButtonContainer with-curtain">
<button class="playa cover" type="button" aria-label="Open" data-container="play1"></button>
<button class="playb cover" type="button" aria-label="Open" data-container="play2"></button>
<button class="playc cover" type="button" aria-label="Open" data-container="play3"></button>
</div>
function showCover(playButton) {
hideAll(config.containers);
resetPage();
markAsPlayed(playButton);
const playButtonContainer = playButton.parentElement;
const container = document.getElementsByClassName(playButton.dataset.container)[0];
playButtonContainer.classList.add("active");
container.classList.add("active");
show(playButtonContainer);
show(container);
}
Second Solution:
function showCover(playButton) {
hideAll(config.containers);
resetPage();
markAsPlayed(playButton);
const playButtonContainer = playButton.parentElement;
const playButtonIndex = Array.from(document.getElementsByClassName('cover')).findIndex(element => element == playButton)
const container = config.containers[playButtonIndex]
playButtonContainer.classList.add("active");
container.classList.add("active");
show(playButtonContainer);
show(container);
}
At this link here: https://jsfiddle.net/j3qh29b7/1/
All the videos appear, where I removed .outer
from the html.
What you will find is, after the curtain closses to go back to the buttons, they just stay stuck in the closed position.
If you may know of a different way to map the buttons to the containers, because these two ways are good, but maybe there could be another way to do this, but I’m not sure.
Currently, at this link here: https://jsfiddle.net/h0dewbka/
.outer
is sitting in the html like this and the code is working fine.
How exactly would it be removed from the html?
</div>
</div>
<button class="exit" type="button" title="Exit" aria-label="Close"></button>
</div>
</div>
<div class="outer"></div>
<div class=" playButtonContainer with-curtain">
<button class="playa cover" type="button" aria-label="Open"></button>
<button class="playb cover" type="button" aria-label="Open"></button>
</div>
Like this?
https://jsfiddle.net/t06rdxj9/1/
<div class="outer container play1 with-curtain">
<div class="outer container play2 with-curtain">
<div class="outer container play3 with-curtain">
<div class="outer container play4 with-curtain">
The curtains are stuck to the ceiling, how would I fix that?
And is there anything else I would adjust in the code after this change was made?
Is there anything in the CSS I would remove that is no longer needed?