Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let wait = false;
  2.  
  3. function setBackground(url) {
  4.   if (wait) return;
  5.   if (background.getAttribute("src") == url) return;
  6.   wait = true;
  7.   let newBackground = document.createElement("img")
  8.   newBackground.id = "newBackground"
  9.   newBackground.className = "background"
  10.   newBackground.style.opacity = 0
  11.   newBackground.style.zIndex = -90
  12.   newBackground.src = url
  13.   background.after(newBackground)
  14.   function start(){ console.log("start"); newBackground.style.opacity = 1 }
  15.   function end(){
  16.     console.log("end")
  17.     background.remove()
  18.     newBackground.id = "background"
  19.     newBackground.style.zIndex = -100
  20.     background = document.getElementById("background")
  21.     wait = false;
  22.   }
  23.  
  24.   newBackground.addEventListener("transitionend", end)
  25.   //setTimeout(end, 2000);
  26.   newBackground.addEventListener("load", () => {
  27.     setTimeout(start, 10);
  28.   })
  29. }
  30. document.addEventListener("DOMContentLoaded", function(){
  31.   background = document.getElementById("background")
  32. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement