1

I have an element, that appears in the page with fade-in animation. Element has an overlay on the whole page when it is clicked (something like modal). It works fine in every browser except Firefox.

Removing animation-fill-mode: both fixes the problem, but I need this property.

const element = document.getElementById('element');
let isClicked = false;

element.addEventListener('click', handleClick, false);

function handleClick() {
 if (isClicked) {
   element.classList.add('isVisible');
  } else {
   element.classList.remove('isVisible');
  }
  
  isClicked = !isClicked;
}
.element {
  width: 200px;
  height: 40px;
  background: red;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  animation-delay: 100ms;
  animation-timing-function: ease;
  animation-duration: 200ms;
  animation-name: fadeIn;
  /* animation-fill-mode: both; */
}

.isVisible {
 ::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: tomato;
    z-index: -1;
    animation-timing-function: ease;
    animation-duration: 300ms;
    animation-name: fadeIn;
  } 
}


@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-100%);
  }
  
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
<div class="element" id="element">
  <p>
    element
  </p>
</div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415

1 Answers1

0

Please add animation delay for that.. it will may be work.

css

.element {
    animation-delay: 1s;
}
Manikandan2811
  • 831
  • 4
  • 9