-
-
Save dheysonalves/c90358273925917670fac9417ff363ec to your computer and use it in GitHub Desktop.
Javascript - Toggling a loading screen with jQuery ajax
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
.loading-container { | |
position:absolute; | |
top:0; | |
right:0; | |
bottom:0; | |
left:0; | |
display:none; | |
} | |
.loading-container:before { | |
position:absolute; | |
top:50%; | |
left:50%; | |
display:block; | |
width:100px; | |
height:100px; | |
line-height:100px; | |
margin:-50px 0 0 -50px; | |
color:#fff; | |
text-align:center; | |
background:rgba(0,0,0,.9); | |
-webkit-border-radius: 5px; | |
-moz-border-radius: 5px; | |
border-radius: 5px; | |
content: 'loading...'; | |
} |
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
<div id="loading-container" class="loading-container"></div> | |
<div id="content-container" class="content-container"></div> |
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
$(function () { | |
// Toggle loading container when ajax call | |
var loadingContainer = $('#loading-container', this.el); | |
loadingContainer.ajaxStart(function () { | |
loadingContainer.show(); | |
}); | |
loadingContainer.ajaxStop(function () { | |
loadingContainer.hide(); | |
}); | |
// Ajax call | |
$.getJSON('https://api.github.com/users/maxparm', function (response) { | |
$('#content-container').html('Response ajax call: ' + response.name); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment