Results 1 to 8 of 8

Thread: How to use setTimeout

  1. #1
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default How to use setTimeout

    In the following script, would you guys please show me how to properly enter a setTimeout,
    or delay, in order that "#info-box" fades in 3 seconds after "#bgAudio" starts playing?

    Thanks

    Code:
    <script>
    jQuery(function($) { 
    
      $('#bgAudio').trigger('play').animate({volume: 1}, 6000);
    		
    	$('#bgAudio').on('playing', function() {
    		$("#info-box").fadeIn();
    		});
    	$('#bgAudio').on('ended', function() {
    		$("#info-box").fadeOut();
    		});
    	});
    
    </script>
    Last edited by KennyP; 02-24-2015 at 11:51 AM.

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Untested, but delay() should do it - more info here: http://api.jquery.com/delay/
    Code:
    jQuery(function($) { 
    
      $('#bgAudio').trigger('play').animate({volume: 1}, 6000);
    		
    	$('#bgAudio').on('playing', function() {
    		$("#info-box").delay(3000).fadeIn();
    		});
    	$('#bgAudio').on('ended', function() {
    		$("#info-box").fadeOut();
    		});
    	});
    If you need more help, please provide a link to a test page.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. The Following User Says Thank You to Beverleyh For This Useful Post:

    KennyP (02-25-2015)

  4. #3
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default

    Thank you so much for taking the time to reply Beverley.
    Unfortunately tho, it doesn't seem to work. I'd like to
    get #info-box elements to display after everything else.

    Because of additional issues this site needs work with, I
    made a duplicate test site here.

  5. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Hi,

    I pulled up an old demo from an earlier thread and added the jQuery delay function: http://fofwebdesign.co.uk/template/_...n-timeline.php It works as expected here so the only thing I can think is that there is something else on your page that is causing conflicts.

    My advice would be to strip the other scripts and elements back as much as you can until you (hopefully) find the conflicting obstacle.

    Hope this helps
    Last edited by Beverleyh; 02-25-2015 at 01:09 PM.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  6. The Following User Says Thank You to Beverleyh For This Useful Post:

    KennyP (02-25-2015)

  7. #5
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default

    Thanks again Beverley. I tried removing other scripts one at a time but no luck.
    If you would show me how, I'd like to try a setTimeout for the entire info box,
    sound and visual. Hopefully that might work?
    Last edited by KennyP; 02-25-2015 at 08:29 PM.

  8. #6
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I'm on iPhone at the moment which sadly doesn't support auto-play, but I've tried to test as best I can and the timeout below appears to delay the fadein info box too in my stripped-back test page;
    Code:
    	$('#bgAudio').on('playing', function() {
    		setTimeout(function() { $('#info-box').fadeIn(); }, 3000);
    		});
    To delay the audio auto-play as well, try moving the setTimeout function to the outside instead (this is the part I have no way of testing at the moment) More info on how to use setTimeout with JQuery here: http://www.sitepoint.com/settimeout-example/
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  9. The Following User Says Thank You to Beverleyh For This Useful Post:

    KennyP (02-27-2015)

  10. #7
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    From memory, your website is now running on Wordpress?

    I don't use Wordpress so can't really offer any specific help for it, but you might also want to read up on jQuery conflicts within Wordpress http://stackoverflow.com/questions/1...dpress-plugins
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  11. The Following User Says Thank You to Beverleyh For This Useful Post:

    KennyP (02-27-2015)

  12. #8
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default

    Many thanks Beverley. Unfortunately the setTimeout doesn't work either, and you're right about Wordpress.
    The way it's setup it has caused many other issues besides this one. Before going on with other site
    additions/embellishments I will strip the entire site off WP. When it functions properly, I'll resume the rest of
    the work on it.

Similar Threads

  1. setTimeout()
    By james438 in forum JavaScript
    Replies: 0
    Last Post: 02-04-2011, 09:45 PM
  2. setTimeout() help
    By tbobker in forum JavaScript
    Replies: 6
    Last Post: 11-19-2008, 09:37 AM
  3. setTimeout vagaries
    By jscheuer1 in forum JavaScript
    Replies: 7
    Last Post: 10-22-2008, 10:42 PM
  4. SetTimeout help
    By itsjareds in forum JavaScript
    Replies: 7
    Last Post: 07-01-2008, 06:51 PM
  5. setTimeOut !!!
    By khaled450 in forum JavaScript
    Replies: 9
    Last Post: 11-11-2007, 09:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •