How do I make a div fade in over a set time?

45 Views Asked by At

I want to make my div box fade in but it never appears.

The first time I tried to use a loop but that made an infinite loop and crashed because I put a timeout in it.

Now I'm trying to use a function that adds 0.1 opacity to the object every set amount of time until it is at max 1 but nothing happens-

function fadethis1 (fadeObjectIn) {debugger
   if (fadeObjectIn.style.opacity>1){
  setTimeout(() => {
    fadeObjectIn.style.opacity=fadeObjectIn.style.opacity+0.1
    fadeObjectIn.style.opacity=parseFloat(fadeObjectIn.style.opacity)+0.1
  }, 100);
    
  fadethis1(document.querySelector("div.alertbox")) }
}
0

There are 0 best solutions below