Solved

Jquery or javascript delay 10 seconds

Posted on 2013-01-17
7
707 Views
Last Modified: 2013-01-17
Hi E's, I have a site that if the client does not nothing, I do launch of a demonstration after 10 seconds.
What I want to know is how I can know if the 10 seconds have passed and launch the function "demo".

The best regards, JC
0
Comment
Question by:Pedro Chagas
  • 4
  • 3
7 Comments
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
what do you call nothing?
0
 
LVL 3

Author Comment

by:Pedro Chagas
Comment Utility
Hi @leakim971, I will call the function "function demo()".
In resume, after 10 seconds start the function.

~JC
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
yes but << nothing >> is what for you?

no keypress?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 3

Author Comment

by:Pedro Chagas
Comment Utility
Oh I see!
I create a game, and if the visitor is the first time that visit my site (for detect that I will use cookies from php), after 10 seconds I launch a demonstration for teach how the game works. The 10 seconds start to count when the page is loaded.
If the visitor wants to stop the demonstration I made available a button for visitor stop see the demo.
That is the base for I need to wait 10 seconds.
I can show you the project: http://rdsrc.us/5J4XG4 (click in the photo to see work the game).

~JC
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
ok so here the logic :
- when starting the game you set a timer to 10s
- if the user do something (click on the button if I well understood) you reset the timer
- if the user lost, you set the timer to 10s

so you need :
var mytimer = setTimeout(function() { demo(); }, 10000);

$(document).ready(function() {
      $("#your_button_id").click(function() {
           clearTimeout(mytimer);
      })
})

function hall_of_fame() { // the function you run when the user loose
       mytimer = setTimeout(function() { demo(); }, 10000);
       // your current code below
}

Open in new window

0
 
LVL 3

Author Comment

by:Pedro Chagas
Comment Utility
Hi, the function setTimeout is what I need.
No, you don't understand the idea or my explanation not was the best.
In normal sites we don't need demonstrations, but when the subject is a game, and if you never play that game before, you will need help. And that was I will offer to my visitors, with the purpose not lost visitors.
When visitor load the page, if they start to play I not will launch the demo, but if they don't start the game in the first 10 seconds I will launch the demo. Is just that.
Made this experience, go to the project (link in my last post), and tell me if you don't feel lost. If I launch the demo, I increase the probabilities for the visitor don't go out...
So, this line is just what I need for now:
var mytimer = setTimeout(function() { demo(); }, 10000);

The best regards, JC
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
yes, you right, adding a demo is a very good idea, I would prefer to see it from the beggining without waiting the 10s and break it asap the user click somewhere to say << I want to play >>

thanks for the points
have fun dev
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now