2017-04-14 53 views
0

我想知道如何更改我的背景Id加載。現在背景設置爲預加載器的顏色。我已經想出瞭如何在身體負荷上隱藏裝載機,但有人幫助我如何將背景改爲圖片。另外,當裝載程序存在時,彈出窗體的元素以便隱藏它的任何解決方案?後臺鏈接位於後臺1 ID中。更改背景ID加載

https://www.w3schools.com/code/tryit.asp?filename=FEMJ1DP31QMZ

function hidespinner() { 
 
    document.getElementById('spinner').style.display = 'none'; 
 
    document.getElementById('heading').style.display = 'none'; 
 
    document.getElementById('background1').style.display.backgroundImage = 'url(https://s28.postimg.org/rbexyjiil/IFBAKGROUND1.jpg)'; 
 
}
html { 
 
    background-color: #ace5f4; 
 
    background-size: cover; 
 
} 
 

 
#spinner { 
 
    height: 50px; 
 
    width: 50px; 
 
    left: 0; 
 
    top: 0; 
 
    bottom: 0; 
 
    left: 0; 
 
    right: 0; 
 
    margin: auto; 
 
    position: fixed; 
 
} 
 

 
#spinner .inner { 
 
    height: 50px; 
 
    width: 50px; 
 
    position: absolute; 
 
    border: 5px solid transparent; 
 
    opacity: 0.7; 
 
    border-radius: 100%; 
 
    animation-name: rotate; 
 
    animation-iteration-count: infinite; 
 
    animation-timing-function: ease; 
 
} 
 

 
#spinner .inner:nth-child(1) { 
 
    border-top-color: white; 
 
    border-bottom-color: white; 
 
    animation-duration: 2s; 
 
} 
 

 
#spinner .inner:nth-child(2) { 
 
    border-left-color: #3bb3ee; 
 
    border-right-color: #3bb3ee; 
 
    animation-duration: 3s; 
 
} 
 

 
#spinner .inner:nth-child(3) { 
 
    border-top-color: #34abdb; 
 
    border-bottom-color: #34abdb; 
 
    animation-duration: 4s; 
 
} 
 

 
@keyframes rotate { 
 
    from { 
 
    transform: rotate(0deg) 
 
    } 
 
    to { 
 
    transform: rotate(360deg) 
 
    } 
 
} 
 

 
#heading { 
 
    color: white; 
 
    font-family: Helvetica; 
 
    text-align: center; 
 
    font-size: 72px; 
 
} 
 

 
#background1 { 
 
    background: url(https://s28.postimg.org/rbexyjiil/IFBAKGROUND1.jpg) no-repeat center fixed; 
 
    background-size: cover; 
 
}
<link rel="shortcut icon" type="image/png" href="https://image.flaticon.com/icons/png/128/222/222506.png"> 
 

 
<!-- Tell the browser to be responsive to screen width --> 
 
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"> 
 

 
<!-- Fonts Awesome CSS --> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css"> 
 

 
<!-- jQuery --> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> 
 

 
<body onload="hidespinner()"> 
 
    <h1 id="heading"><i class="fa fa-plane"></i> v<strong>Crew</strong></h1> 
 
     <div id="spinner"> 
 
     <div class="inner"></div> 
 
     <div class="inner"></div> 
 
     <div class="inner"></div> 
 
     </div> 
 
     Hello Is the spinner on? 
 
</body>

請看到,即使是當前的代碼是有版權的。我還想將這個加載器添加到頁面中,這樣任何人都可以提出如何添加它或將其添加到網頁並給我代碼。

https://www.w3schools.com/code/tryit.asp?filename=FEAZZM840UQS

function hideloader() { 
 
    document.getElementById("loading").style.display = "none"; 
 
}
@import url('https://fonts.googleapis.com/css?family=Spirax'); 
 
@import url('https://fonts.googleapis.com/css?family=Indie+Flower|Spirax'); 
 

 
body { 
 
    background-color: #58e8f8; 
 
} 
 

 
.silly { 
 
    color: white; 
 
    text-align: center; 
 
    font-family: "Indie Flower" 
 
} 
 

 
.spinner { 
 
    width: 80px; 
 
    height: 80px; 
 
    position: fixed; 
 
    left: 0; 
 
    right: 0; 
 
    top: 0; 
 
    bottom: 0; 
 
    margin: auto; 
 
} 
 

 
.double-bounce1, 
 
.double-bounce2 { 
 
    width: 100%; 
 
    height: 100%; 
 
    border-radius: 50%; 
 
    background-color: white; 
 
    opacity: 0.6; 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    -webkit-animation: sk-bounce 2.0s infinite ease-in-out; 
 
    animation: sk-bounce 2.0s infinite ease-in-out; 
 
} 
 

 
.double-bounce2 { 
 
    -webkit-animation-delay: -2.0s; 
 
    animation-delay: -1.0s; 
 
} 
 

 
@-webkit-keyframes sk-bounce { 
 
    0%, 
 
    100% { 
 
    -webkit-transform: scale(0.0) 
 
    } 
 
    50% { 
 
    -webkit-transform: scale(1.0) 
 
    } 
 
} 
 

 
@keyframes sk-bounce { 
 
    0%, 
 
    100% { 
 
    transform: scale(0.0); 
 
    -webkit-transform: scale(0.0); 
 
    } 
 
    50% { 
 
    transform: scale(1.0); 
 
    -webkit-transform: scale(1.0); 
 
    }
<title>Page Title</title> 
 
<script type="text/javascript" src="https://gc.kis.v2.scr.kaspersky-labs.com/88CE1C4C-84C0-9E49-A763-9D3DCEC43907/main.js" charset="UTF-8"></script> 
 

 
<body onload="hideloader"> 
 
    <h1 class="silly"> vCrew </h1> 
 

 
    <div id="loading" class="spinner"> 
 
    <div class="double-bounce1"></div> 
 
    <div class="double-bounce2"></div> 
 
    </div> 
 
</body>

將這工作w3schools.com/code/tryit.asp?filename=FEMJIZCDHJBW?

+3

歡迎SO。請先到[幫助中心](http://stackoverflow.com/help),然後閱讀[如何提問](http://stackoverflow.com/help/how-to-ask)並提供[MCVE :最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。如果周圍的人可以輕鬆地閱讀和理解你的意思,或問題是什麼,他們會更願意幫助:)但請記住,SO是一個有幫助的社區,所以請向我們展示一些你搞砸了的代碼與我們將很樂意幫助改善它... – OldPadawan

+1

您可能需要使用一些JavaScript。 –

+0

我創建了此響應於另一個加載相關的問題:http://stackoverflow.com/a/25253988/1762224 –

回答

0

您可以嘗試在內容頂部添加加載div,並隱藏/顯示加載順序,直到數據存在。

onReady(function() { 
 
    toggleClass(document.getElementById('page'), 'hidden'); 
 
    toggleClass(document.getElementById('loading'), 'hidden'); 
 
}); 
 

 
function onReady(callback) { 
 
    var intervalID = window.setInterval(function checkReady() { 
 
    if (document.getElementsByTagName('body')[0] !== undefined) { 
 
     window.clearInterval(intervalID); 
 
     callback.call(this); 
 
    } 
 
    }, 1000); 
 
} 
 

 
// http://youmightnotneedjquery.com/ 
 
function toggleClass(el, className) { 
 
    if (el.classList) el.classList.toggle(className); 
 
    else { 
 
    var classes = el.className.split(' '); 
 
    var existingIndex = classes.indexOf(className); 
 
    if (existingIndex >= 0) classes.splice(existingIndex, 1); 
 
    else classes.push(className); 
 
    el.className = classes.join(' '); 
 
    } 
 
}
body { 
 
    background: #FFF url("http://i.imgur.com/KheAuef.png") top left repeat-x; 
 
    font-family: "Brush Script MT", cursive; 
 
} 
 

 
h1 { 
 
    font-size: 2em; 
 
    margin-bottom: 0.2em; 
 
    padding-bottom: 0; 
 
} 
 

 
p { 
 
    font-size: 1.5em; 
 
    margin-top: 0; 
 
    padding-top: 0; 
 
} 
 

 
#loading { 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    z-index: 100; 
 
    width: 100vw; 
 
    height: 100vh; 
 
    background-color: rgba(192, 192, 192, 0.9); 
 
    background-image: url("http://i.stack.imgur.com/MnyxU.gif"); 
 
    background-repeat: no-repeat; 
 
    background-position: center; 
 
} 
 

 
.hidden { 
 
    display: none !important; 
 
}
<script src="https://rawgit.com/bgrins/loremjs/master/lorem.js"></script> 
 
<div id="page" class="hidden"> 
 
    <h1>The standard Lorem Ipsum passage</h1> 
 

 
    <div class="content" data-lorem="7s"></div> 
 
</div> 
 
<div id="loading"></div>