Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Jquery or javascript delay 10 seconds

Posted on 2013-01-17
7
Medium Priority
?
759 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
ID: 38790059
what do you call nothing?
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 38790082
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
ID: 38790105
yes but << nothing >> is what for you?

no keypress?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Author Comment

by:Pedro Chagas
ID: 38790143
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 2000 total points
ID: 38790157
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
ID: 38790226
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
ID: 38790323
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

963 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