Last active
May 20, 2017 14:02
-
-
Save asduser/113cfed717657eb932377e02a277e23e to your computer and use it in GitHub Desktop.
Images loaded events & suaitable loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mainContainer = $("#main"); | |
var loader = $(".load-bar"); | |
mainContainer.imagesLoaded() | |
.always( function( instance ) { | |
console.log('all images loaded'); | |
toggleElements(); | |
}) | |
.done( function( instance ) { | |
console.log('all images successfully loaded'); | |
}) | |
.fail( function() { | |
console.log('all images loaded, at least one is broken'); | |
}) | |
.progress( function( instance, image ) { | |
var result = image.isLoaded ? 'loaded' : 'broken'; | |
console.log( 'image is ' + result + ' for ' + image.img.src ); | |
}); | |
function toggleElements() { | |
loader.fadeToggle(10); | |
mainContainer.fadeToggle(500); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<link rel="stylesheet" href="style.css" type="text/css" /> | |
<title>Title</title> | |
</head> | |
<body> | |
<div id="main" class="container"> | |
<img src="http://itc.ua/wp-content/uploads/2016/10/Google-Wallpaper-Good-Full-HD.png" /> | |
<img src="http://wallpapercave.com/wp/LrITsWf.jpg" /> | |
<img src="http://wallpapercave.com/wp/EQAEzcs.jpg" /> | |
<img src="https://3.bp.blogspot.com/-jhNk7x6GRaw/TfYMHih9U-I/AAAAAAAAAB8/CAJFItvCGaw/s1600/Mountain-Rainstorm-Screensaver_yfkg.jpg" /> | |
<img src="http://i.imgur.com/qmkEKd9.jpg" /> | |
<img src="https://s-media-cache-ak0.pinimg.com/originals/2b/34/b0/2b34b03ce6fcf5bd61eb01fce878d665.jpg" /> | |
</div> | |
<div class="load-bar"> | |
<div class="bar"></div> | |
<div class="bar"></div> | |
<div class="bar"></div> | |
</div> | |
<script src="https://code.jquery.com/jquery-3.2.1.js"></script> | |
<script src="https://unpkg.com/imagesloaded@4/imagesloaded.pkgd.js"></script> | |
<script src="app.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#main { | |
display: none; | |
} | |
#main > img { | |
width: 200px; | |
height: 200px; | |
} | |
.load-bar { | |
position: relative; | |
margin-top: 20px; | |
width: 100%; | |
height: 6px; | |
background-color: #fdba2c; | |
} | |
.bar { | |
content: ""; | |
display: inline; | |
position: absolute; | |
width: 0; | |
height: 100%; | |
left: 50%; | |
text-align: center; | |
} | |
.bar:nth-child(1) { | |
background-color: #da4733; | |
animation: loading 3s linear infinite; | |
} | |
.bar:nth-child(2) { | |
background-color: #3b78e7; | |
animation: loading 3s linear 1s infinite; | |
} | |
.bar:nth-child(3) { | |
background-color: #fdba2c; | |
animation: loading 3s linear 2s infinite; | |
} | |
@keyframes loading { | |
from {left: 50%; width: 0;z-index:100;} | |
33.3333% {left: 0; width: 100%;z-index: 10;} | |
to {left: 0; width: 100%;} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment