coderslay
coderslay

Reputation: 14370

How to apply delay to load something in jquerymobile

I need to apply a delay for something after loading of a page.The delay can be of 5 seconds and then i need to load some components.How to do that?

Upvotes: 0

Views: 2305

Answers (3)

Chan
Chan

Reputation: 2641

Since you are using jQuery mobile already go for the

.delay()

from jQuery. http://api.jquery.com/delay/

There is also a another question like this. Beware jQuery docs states this -

The .delay() method is best for delaying between queued jQuery effects. Because it is limited—it doesn't, for example, offer a way to cancel the delay—.delay() is not a replacement for JavaScript's native setTimeout function, which may be more appropriate for certain use cases.

Here is the Example from jQuery doc

<!DOCTYPE html>
<html>
<head>
  <style>
div { position: absolute; width: 60px; height: 60px; float: left; }
.first { background-color: #3f3; left: 0;}
.second { background-color: #33f; left: 80px;}
</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>

<p><button>Run</button></p>
<div class="first"></div>
<div class="second"></div>

<script>
    $("button").click(function() {
      $("div.first").slideUp(300).delay(800).fadeIn(400);
      $("div.second").slideUp(300).fadeIn(400);
    });
</script>

</body>
</html>

Upvotes: 1

Hkachhia
Hkachhia

Reputation: 4539

Use javascript setTimeout() function. e.g setTimeout("function()",5000);

Upvotes: 0

rockerest
rockerest

Reputation: 10508

function loadStuff()
{
    //load stuff
}

setTimeout(function(){loadStuff()}, 5000);

Write your function to do your loading, then call that function after a timeout of 5 seconds.

Upvotes: 0

Related Questions