Wednesday, September 11, 2013

jQuery Show Loading Image While Page Loads or Show Loading Image in Webpage while Page Loads

Introduction

Here I will explain how to use 
jQuery to show loading image while page loading in jQuery or show loading image in webpage while page loading instead of blank page in jQuery.


To show loading image on page load we need to define load function in jQuery during pageload and need to write css class to show loading image for that we need to write code like as shown below

// jQuery Plugin and calling function in page load
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(window).load(function() {
$("#pageloaddiv").fadeOut(2000);
});
</script>

// CSS Class
<style type="text/css">
#pageloaddiv {
positionfixed;
left0px;
top0px;
width100%;
height100%;
z-index1000;
backgroundurl('pageloader.gif') no-repeat center center;
}
</style>

// loading div to show loading image
<div id="pageloaddiv"></div>

If you want check this code in complete example check below code

Example:


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Show Loading Image while Page loading</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(window).load(function() {
$("#pageloaddiv").fadeOut(2000);
});
</script>
<style type="text/css">
#pageloaddiv {
positionfixed;
left0px;
top0px;
width100%;
height100%;
z-index1000;
backgroundurl('pageloader.gif') no-repeat center center;
}
</style>
</head>
<body>
<div id="pageloaddiv"></div>
</body>
</html>
Live Demo



source : http://www.aspdotnet-suresh.com/2013/09/jquery-show-loading-image-while-page-loads.html

No comments:

Post a Comment