Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let wait = false;
- function setBackground(url) {
- if (wait) return;
- if (background.getAttribute("src") == url) return;
- wait = true;
- let newBackground = document.createElement("img")
- newBackground.id = "newBackground"
- newBackground.className = "background"
- newBackground.style.opacity = 0
- newBackground.style.zIndex = -90
- newBackground.src = url
- background.after(newBackground)
- function start(){ console.log("start"); newBackground.style.opacity = 1 }
- function end(){
- console.log("end")
- background.remove()
- newBackground.id = "background"
- newBackground.style.zIndex = -100
- background = document.getElementById("background")
- wait = false;
- }
- newBackground.addEventListener("transitionend", end)
- //setTimeout(end, 2000);
- newBackground.addEventListener("load", () => {
- setTimeout(start, 10);
- })
- }
- document.addEventListener("DOMContentLoaded", function(){
- background = document.getElementById("background")
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement