This slider is runnning in an animation loop unless one of the dots at the top is clicked. Then, the animated elements (the <span>
dots and the <figure>
s) get a style that stop the animation.
<section id="slider">
<span class="control" tabindex="1"></span>
<span class="control" tabindex="2"></span>
<span class="control" tabindex="3"></span>
<figure class="slide">
<!--Image 1--->
</figure>
<figure class="slide">
<!--Image 2--->
</figure>
<figure class="slide">
<!--Image 3--->
</section>
Script:
window.onload = function () {
var slider = document.querySelector('#slider');
var animated = slider.querySelectorAll('.control, .slide');
function switchAll (focus) {
animated.forEach(function (el) {
el.style['animation-name'] = focus ? 'none' : null;
});
}
document.querySelector('body').addEventListener('click', function (e) {
switchAll(slider.querySelector('.control:focus'));
});
};
After the animation is stopped, it should restart if something other than the dots is clicked (so that they loose focus). But on Firefox this works only if the click is outside of the #slider
.
Clicking inside the currently shown <figure>
lets it disappear - this is expected CSS behavior, since no dot has the focus. But the animation does not restart; the first click
event does not reach the <body>
. Only a second click triggers the event listener.
I've also tried to attach the event to the #slider
, but the result is the same. It seems as if the event would not bubble past the <figure>
elements, attaching it on those works, but is obviously a inferior solution.
Anyway I'd like to understand what happens to the event.