์น ์ฌ์ดํธ์ ์ง์ค์ ์ธ ํธ์ถ์ํ๋ ๋์ ์๋นํ ๋๋ฆฌ๊ฒ๋ก๋๋๋ ์น์ ์ด ์์ต๋๋ค.
div
ํ์ด์ง๊ฐ ์ค๋น๋๋ ๋์ ํ์ํ๊ณ ๋ชจ๋ ์ค๋น๊ฐ๋๋ฉด ์ฌ๋ผ์ง๋ โ๋ก๋ ์คโ๊ณผ ๋น์ทํ ๋ง์ ํ ์์๋ ์์ด๋์ด ๊ฐ ์์ต๋๊น?
๋ต๋ณ
๋๋ ์ด๊ฒ์ ํ์๋กํ๊ณ ์ฝ๊ฐ์ ์ฐ๊ตฌ ํ์ ๋๋ ์ด๊ฒ์ ์๊ฐํด ๋๋ค ( jQuery๊ฐ ํ์ํ๋ค) :
๋จผ์ <body>
ํ๊ทธ ๋ฐ๋ก ๋ค์์ ๋ค์์ ์ถ๊ฐํ์ญ์์ค.
<div id="loading">
<img id="loading-image" src="images/ajax-loader.gif" alt="Loading..." />
</div>
๊ทธ๋ฐ ๋ค์ div ๋ฐ ์ด๋ฏธ์ง์ ์คํ์ผ ํด๋์ค๋ฅผ CSS์ ์ถ๊ฐํ์ญ์์ค.
#loading {
width: 100%;
height: 100%;
top: 0;
left: 0;
position: fixed;
display: block;
opacity: 0.7;
background-color: #fff;
z-index: 99;
text-align: center;
}
#loading-image {
position: absolute;
top: 100px;
left: 240px;
z-index: 100;
}
๊ทธ๋ฐ ๋ค์์ด ์๋ฐ ์คํฌ๋ฆฝํธ๋ฅผ ํ์ด์ง์ ์ถ๊ฐํ์ญ์์ค (๋ฐ๋์งํ๊ฒ๋ ํ์ด์ง ๋, ๋ซ๋ </body>
ํ๊ทธ ์ ).
<script>
$(window).load(function() {
$('#loading').hide();
});
</script>
๋ง์ง๋ง์ผ๋ก background-colour
์คํ์ผ ํด๋์ค ๋ฅผ ์ฌ์ฉํ์ฌ ๋ก๋ฉ ์ด๋ฏธ์ง์ ์์น์ ๋ก๋ฉ div ์ ์์น๋ฅผ โโ์กฐ์ ํ์ญ์์ค .
์ด๊ฒ์ด ์ ์๋ํฉ๋๋ค. ๊ทธ๋ฌ๋ ๋ฌผ๋ก ajax-loader.gif
์ด๋๊ฐ์ ์์ด์ผํฉ๋๋ค . ์ฌ๊ธฐ ๊ณต์ง . (์ค๋ฅธ์ชฝ ํด๋ฆญ> ๋ค๋ฅธ ์ด๋ฆ์ผ๋ก ์ด๋ฏธ์ง ์ ์ฅ โฆ)
๋ต๋ณ
์ด ์คํฌ๋ฆฝํธ๋ ํ์ด์ง๊ฐ๋ก๋ ๋ ๋ ์ ์ฒด ์ฐฝ์ ๋ฎ๋ div๋ฅผ ์ถ๊ฐํฉ๋๋ค. CSS ์ ์ฉ ๋ก๋ฉ ์คํผ๋๊ฐ ์๋์ผ๋ก ํ์๋ฉ๋๋ค. ์๋์ฐ (๋ฌธ์๊ฐ ์๋)์ ๋ก๋ฉ์ด ์๋ฃ ๋ ๋๊น์ง ๊ธฐ๋ค๋ฆฐ ๋ค์ ์ต์ ์ผ๋ก ๋ช ์ด ๋ ๊ธฐ๋ค๋ฆฝ๋๋ค.
- jQuery 3๊ณผ ํจ๊ป ์๋ํฉ๋๋ค (์๋ก์ด ์ฐฝ๋ก๋ ์ด๋ฒคํธ๊ฐ ์์ต๋๋ค)
- ์ด๋ฏธ์ง๊ฐ ํ์ํ์ง ์์ง๋ง ์ฝ๊ฒ ์ถ๊ฐ ํ ์ ์์ต๋๋ค
- ๋ ๋ง์ ๋ธ๋๋ฉ ๋๋ ์ง์นจ์ ๋ํ ์ง์ฐ ๋ณ๊ฒฝ
- ์์กด์ฑ์ jQuery์ ๋๋ค.
https://projects.lukehaas.me/css-loaders์ CSS ๋ก๋ ์ฝ๋
$('body').append('<div style="" id="loadingDiv"><div class="loader">Loading...</div></div>');
$(window).on('load', function(){
setTimeout(removeLoader, 2000); //wait for page load PLUS two seconds.
});
function removeLoader(){
$( "#loadingDiv" ).fadeOut(500, function() {
// fadeOut complete. Remove the loading div
$( "#loadingDiv" ).remove(); //makes page more lightweight
});
}
.loader,
.loader:after {
border-radius: 50%;
width: 10em;
height: 10em;
}
.loader {
margin: 60px auto;
font-size: 10px;
position: relative;
text-indent: -9999em;
border-top: 1.1em solid rgba(255, 255, 255, 0.2);
border-right: 1.1em solid rgba(255, 255, 255, 0.2);
border-bottom: 1.1em solid rgba(255, 255, 255, 0.2);
border-left: 1.1em solid #ffffff;
-webkit-transform: translateZ(0);
-ms-transform: translateZ(0);
transform: translateZ(0);
-webkit-animation: load8 1.1s infinite linear;
animation: load8 1.1s infinite linear;
}
@-webkit-keyframes load8 {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes load8 {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#loadingDiv {
position:absolute;;
top:0;
left:0;
width:100%;
height:100%;
background-color:#000;
}
This script will add a div that covers the entire window as the page loads. It will show a CSS-only loading spinner automatically. It will wait until the window (not the document) finishes loading.
<ul>
<li>Works with jQuery 3, which has a new window load event</li>
<li>No image needed but it's easy to add one</li>
<li>Change the delay for branding or instructions</li>
<li>Only dependency is jQuery.</li>
</ul>
Place the script below at the bottom of the body.
CSS loader code from https://projects.lukehaas.me/css-loaders
<!-- Place the script below at the bottom of the body -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
๋ต๋ณ
window.onload = function(){ document.getElementById("loading").style.display = "none" }
#loading {width: 100%;height: 100%;top: 0px;left: 0px;position: fixed;display: block; z-index: 99}
#loading-image {position: absolute;top: 40%;left: 45%;z-index: 100}
<div id="loading">
<img id="loading-image" src="img/loading.gif" alt="Loading..." />
</div>
JS์์ ๋ง๋ค์ด์ง ๊ฐ์ฅ ๊ฐ๋จํ ํ์ด๋ ์์ ํจ๊ณผ๋ฅผ ๊ฐ์ง ์ด๋ฏธ์ง ๋ก๋ฉ ์ด๋ฏธ์ง :
๋ต๋ณ
๋๋ ๋๋ฅผ ์ํด ์๋ฒฝํ๊ฒ ํจ๊ณผ๊ฐ์๋ ๋ ๋ค๋ฅธ ๊ฐ๋จํ ํด๊ฒฐ์ฑ ์ ๊ฐ์ง๊ณ ์์ต๋๋ค.
๋จผ์ ์๋ ํ์๋ ๊ฒ์ฒ๋ผ GIF๋ฅผ๋ก๋ํ๋ฉด์ ํฌ๋ช ์ค๋ฒ๋ ์ด ์ธ Lockon ํด๋์ค ๋ผ๋ ์ด๋ฆ์ CSS๋ฅผ ๋ง๋ญ๋๋ค.
.LockOn {
display: block;
visibility: visible;
position: absolute;
z-index: 999;
top: 0px;
left: 0px;
width: 105%;
height: 105%;
background-color:white;
vertical-align:bottom;
padding-top: 20%;
filter: alpha(opacity=75);
opacity: 0.75;
font-size:large;
color:blue;
font-style:italic;
font-weight:400;
background-image: url("../Common/loadingGIF.gif");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
์ด์ ํ์ด์ง๊ฐ๋ก๋ ๋ ๋๋ง๋ค ์ ์ฒด ํ์ด์ง๋ฅผ ์ค๋ฒ๋ ์ด๋ก ๋ค๋ฃจ๋์ด ํด๋์ค๋ก div๋ฅผ ๋ง๋ค์ด์ผํฉ๋๋ค.
<div id="coverScreen" class="LockOn">
</div>
์ด์ ํ์ด์ง๊ฐ ์ค๋น ๋ ๋๋ง๋ค์ด ํ์ง ํ๋ฉด์ ์จ๊ฒจ์ผํ๋ฉฐ ํ์ด์ง๊ฐ ์ค๋น ๋ ๋๊น์ง ์ฌ์ฉ์๊ฐ ์ด๋ฒคํธ๋ฅผ ํด๋ฆญ / ์คํํ๋ ๊ฒ์ ์ ํ ํ ์ ์์ต๋๋ค.
$(window).on('load', function () {
$("#coverScreen").hide();
});
์์ ํด๊ฒฐ์ฑ ์ ํ์ด์ง๊ฐ๋ก๋ ๋ ๋๋ง๋ค ์ข์ต๋๋ค.
์ด์ ํ์ด์ง๊ฐ๋ก๋ ๋ ํ์ ์ง๋ฌธ์ด ์์ต๋๋ค. ๋ฒํผ์ด๋ ์ด๋ฒคํธ๊ฐ ์ค๋ ๊ฑธ๋ฆด ๋๋ง๋ค ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด ํด๋ผ์ด์ธํธ ํด๋ฆญ ์ด๋ฒคํธ์ ํ์ํด์ผํฉ๋๋ค.
$("#ucNoteGrid_grdViewNotes_ctl01_btnPrint").click(function () {
$("#coverScreen").show();
});
์ฆ,์ด ์ธ์ ๋ฒํผ์ ํด๋ฆญํ๋ฉด (๋ณด๊ณ ์๋ฅผ ์์ฑํ๋ ๋ฐ ์๊ฐ์ด ์ค๋ ๊ฑธ๋ฆผ) ํ์ง๊ฐ GIF๋ก ํ์๋์ด
๋ต๋ณ
๋ด์ฉ์ ๊ธฐ๋ณธ๊ฐ display:none
์ ์ค์ ํ ๋ค์ display:block
์์ ํ๋ก๋ ๋ ํ์ ์ค์ ํ๊ฑฐ๋ ์ด์ ์ ์ฌํ ์ด๋ฒคํธ ์ฒ๋ฆฌ๊ธฐ๋ฅผ ๊ฐ ์ต๋๋ค. ๊ทธ๋ฐ ๋ค์ display:block
โ๋ก๋ ์คโ์ผ๋ก ์ค์ ๋ div๊ฐ ์๊ณ display:none
์ด์ ๊ณผ ๋์ผํ ์ด๋ฒคํธ ํธ๋ค๋ฌ์์ ์ค์ ํ์ญ์์ค .
๋ต๋ณ
๊ธ์, ์ด๊ฒ์ ์ฃผ๋ก โ์ง์ค์ ์ธ ํธ์ถโ์ ํ์ํ ์์๋ฅผ๋ก๋ํ๋ ๋ฐฉ๋ฒ์ ๋ฌ๋ ค ์์ผ๋ฉฐ, ์ด๊ธฐ ์๊ฐ์ ์์ฝ์ค๋ฅผ ํตํด๋ก๋๋ฅผ ์ํํ๋ค๋ ๊ฒ์ ๋๋ค. ์ด ๊ฒฝ์ฐ โbeforeSendโ์ต์ ์ ์ฌ์ฉํ์ฌ ๋ค์๊ณผ ๊ฐ์ด ์์ฝ์ค ํธ์ถ์ ํ ์ ์์ต๋๋ค.
$.ajax({
type: 'GET',
url: "some.php",
data: "name=John&location=Boston",
beforeSend: function(xhr){ <---- use this option here
$('.select_element_you_want_to_load_into').html('Loading...');
},
success: function(msg){
$('.select_element_you_want_to_load_into').html(msg);
}
});
ํธ์ง
์ด ๊ฒฝ์ฐ jQuery 'display:block'/'display:none'
์ ํจ๊ป ์ ์ ์ต์
์ค ํ๋๋ฅผ ์ฌ์ฉ $(document).ready(...)
ํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ์ด $(document).ready()
ํจ์๋ ์คํํ๊ธฐ ์ ์ ์ ์ฒด ๋ฌธ์ ๊ตฌ์กฐ๊ฐ๋ก๋๋๊ธฐ๋ฅผ ๊ธฐ๋ค๋ฆฝ๋๋ค ( ๊ทธ๋ฌ๋ ๋ชจ๋ ๋ฏธ๋์ด๊ฐ๋ก๋ ๋ ๋๊น์ง ๊ธฐ๋ค๋ฆฌ์ง๋ ์์ต๋๋ค ). ๋น์ ์ ์ด๋ฐ ์์ผ๋ก ํ ๊ฒ์
๋๋ค :
$(document).ready( function() {
$('table#with_slow_data').show();
$('div#loading image or text').hide();
});
๋ต๋ณ
๋ด ๋ธ๋ก๊ทธ๋ 100 % ์๋ํฉ๋๋ค.
function showLoader()
{
$(".loader").fadeIn("slow");
}
function hideLoader()
{
$(".loader").fadeOut("slow");
}
.loader {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url('pageLoader2.gif') 50% 50% no-repeat rgb(249,249,249);
opacity: .8;
}
<div class="loader">