Hi Folks at Stack Overflow. I was looking for a way to add a spinner on my website and I found this useful code but the only thing I'm missing is the code for setting the delay or duration on the spinner, I would really like it to show for like 2 seconds. Any suggestions...
<html>
<head>
<script type="text/javascript">
$(window).bind("load", function() {
$('#overlay').fadeOut(function()
{
$('#container').fadeIn();
});
});
</script>
</head>
<body>
<div id="overlay">
<img src="ajax-loader.gif" alt="Loading" />
Loading...
</div>
<div id="container" style="display:none">
</div>
</body>
</html>
Hi Folks at Stack Overflow. I was looking for a way to add a spinner on my website and I found this useful code but the only thing I'm missing is the code for setting the delay or duration on the spinner, I would really like it to show for like 2 seconds. Any suggestions...
<html>
<head>
<script type="text/javascript">
$(window).bind("load", function() {
$('#overlay').fadeOut(function()
{
$('#container').fadeIn();
});
});
</script>
</head>
<body>
<div id="overlay">
<img src="ajax-loader.gif" alt="Loading" />
Loading...
</div>
<div id="container" style="display:none">
</div>
</body>
</html>
Share
asked Jun 6, 2014 at 5:55
xzibitxzibit
3,5072 gold badges19 silver badges19 bronze badges
3
- add a fiddle so that its easy to work with and what you are exactly trying to do – codefreaK Commented Jun 6, 2014 at 5:56
- Here's the fiddle of what I am trying to achieve but I want to know how I can set the duration of the spinner for only 2 or 3 seconds. jsfiddle/HYVv7 – xzibit Commented Jun 6, 2014 at 6:11
- Hey please upvote it also – codefreaK Commented Jun 6, 2014 at 7:25
4 Answers
Reset to default 2Click for Demo show loading pic for 3 seconds and then showing the content[Solved]
HTML
<div id="overlay">
<img src="http://cdn.nirmaltv./images/generatorphp-thumb.gif" alt="Wait" alt="Loading" />
<div id="overlayText">
Wait
Loading
</div>
</div>
<div id="container" >
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
Jquery
var delay = 3000;
setTimeout(function()
{
$( "#overlay" ).fadeOut( "slow" );
$('#container').fadeIn();
},
delay
) ;
CSS
#overlay >img{
position:absolute;
top:300px;
left: 320px;
z-index:10;
}
#overlayText{
position:absolute;
top:365px;
left: 330px;
z-index:11;
}
#container{
position:relative;
display:none;
}
#overlay{
width:100%;
height:100%;
position: absolute;
top:0px;
z-index: 2;
background-color:#222;
opacity:0.7;
}
Use delay(2000)
before fadeOut
.
Here is demo of js fiddle for your code hope it helps
http://jsfiddle/pragneshok/ZQSN3/4/
HTML CODE
<div id="overlay" style="position:absolute;">
Loading...
</div>
<div id="container" style="display:none;background:#000;height:300px;width:300px;">
</div>
JQUERY CODE
$(document).ready(function() {
$('#overlay').fadeOut(2000,function(){
$('#container').fadeIn(1000);
});
});
Just a quick fyi in case someone stumbles upon this question:
Bootstrap has a collection of spinners that is very easy to use. Couple this with animate.css for the fade in and it can be achieved with very little code. see https://getbootstrap./docs/4.5/ponents/spinners/ https://animate.style/
<div class="d-flex justify-content-center animate__animated animate__fadeIn">
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>