Delay, fadeout, remove

I found this javascript code that does what I am looking for.

The only issue is, it is in jquery.

I’m trying to change it to vanilla javascript.

Is there someone who can help me with this?

I was told this is very difficult to do.

$('.curtain').click(function() {
          $('.fadeout').delay(500).fadeOut(3000, function() {

Which would then be added to this code.

(function iife() {
      "use strict";
      function show(el) {
      function hide(el) {
      function coverClickHandler(evt) {
        const cover = evt.currentTarget;
        const curtain = document.querySelector(".curtain");
        const thewrap = curtain.parentElement.querySelector(".container");
      const cover = document.querySelector(".jacketa");
      cover.addEventListener("click", coverClickHandler);

So what exactly is it, in steps, that you’re trying to accomplish? In terms of both visual and structural changes? In the jQuery version, the button is clicked and a half second later the button begins to fade, taking three seconds to do so, at which point the faded button is removed from the DOM.

Are you looking to do something similar? If so, there are some useful things to research. First, setTimeOut will let you schedule something to happen at some future point. Second, take a look at CSS transitions, this could handle the fade cleanly. And lastly, there is a DOM event to listen to CSS transitions. In this case transitionend.


1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.