Why does it disappear smoothly, but appears abruptly (transition: opasity)?

  • 0
    There is a block that, when the button is clicked, should fade out and appear thanks to js:
    document.getElementsByTagName('div')[0].style.opacity = '0';
    setTimeout(()=> {
        document.getElementsByTagName('div')[0].style.opacity = '1';
    }, 1000);


    div {
        transition: opacity 1s ease;
    }


    <div>
        <p>Привет, стиль..</p>
    </div>

    But it turns out that it only smoothly disappears, and appears - abruptly.

    Please tell me how to fix this.
    JavaScript Anonymous, Aug 12, 2020

  • 1 Answers
  • 0
    Either decrease the transit or increase the timeout. If the js changes the fear before the animation ends, then an instant transition is obtained.
    Juliet Weiss

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!