I created a transition that makes the page go white when switching to another page, and it works well, but as I noticed if I use the built in 'back' button then it redirects to the previous page and then redirects back to the same site I pressed the 'back' button.
Here is the HTML: <div class="transition transition-1 is-active"></div>
Css:
.transition-1 {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 101;
background-color: white ;
opacity: 0;
pointer-events: none;
transition: 0.5s ease-out;
}
.transition-1.is-active {
pointer-events: all;
opacity: 1;
}
And where the problem comes from - the JS:
window.onload = (event) => {
const anchors = document.querySelectorAll('nav a');
const transition_el = document.querySelector('.transition');
setTimeout(() => {
transition_el.classList.remove('is-active');
}, 500);
for (let i = 0; i < anchors.length; i++) {
const anchor = anchors[i];
anchor.addEventListener('click', e => {
e.preventDefault();
let target = e.target.href;
transition_el.classList.add('is-active');
setInterval(() => {
window.location.href = target;
}, 500);
// I think this gets stuck over and over again and it loads when you want to go back
})
}
}
Is there a way from preventing it from doing this?