•      
  • Garbage Burrito!An online internet web blog by Ben Kittrell
  • Blog
  • Tweets
  • Contact
  • Photos
  • Favorite Burrito
  • Burrito Shop
  • Cart
  • Login
  •      
 View Cart Register Login        

Garbage Burrito!

An online internet web blog by Ben Kittrell

  • Blog
  • Tweets
  • Contact
  • Photos
  • Favorite Burrito
  • Burrito Shop

 About Ben

Co-Founder of Doodlekit. Coder, Home Renovator, Enjoyer of Refreshing Beverages.

Sometimes I blog here, sometimes on Doodlekit, sometimes I tweet and now I podcast.

Most recently I've been doing software development strategy consulting for Kansas City businesses.  

 Doodlekit

Doodlekit is the easiest way for small businesses to create their own website.  Used by millions in over 180 countries.

Follow us for updates.

Doodlekit on Twitter
AngelList
LinkedIn
Facebook

160x600.gif

free website builder

 

 Blog Entries

  • Great Review of Doodlekit by Comparakeet
  • New Podcast Episode - Danny O'Neill - The Roasterie - Spare Room Radio
  • What I Wish Someone Told Me Before I Started Buying Podcast Equipment
  • Announcing Spare Room Radio - New Podcast
  • Google Fiber Experiment: Cloud Video Transcoding
more  

 Blog Comments

  • slfkdlskf: Variable Arguments with Callback in CoffeeScript
  • kdsjfsj: Moving Towards a More Segmented Internet
  • sjksv: Printing Pestulant Popups
  • Newt Scamander Coat Replica: Great Review of Doodlekit by Comparakeet
  • status: Calling for a better HTML File Input
more  

 Links


  • website reviewer
  • live on - sharing memories
  • kids website builder
  • resume website
  • martial arts website builder
  • affiliate website builder
  • teacher website

 Login

 Forgot Password?
 Register

 Forum Posts

  • rajablogid: RE: Stupid Simple, Yet Effective
  • JohnFGlenn: RE: Stupid Simple, Yet Effective
  • Ben Kittrell : RE: Stupid Simple, Yet Effective
  • Ben Kittrell : RE: Stupid Simple, Yet Effective
  • Kevin Perdue: RE: Stupid Simple, Yet Effective
more  

 Custom Login

 Forgot Password?
 Register

 Back to Blog

Slideshow / Clearing All Javascript Timers

Ben Kittrell
 05/31/2007 07:07PM

I decided to whip up a slideshow for the photo albums, since a few people have asked for it.  First I thought about finding a flash one, but I knew that it would probably ask for a simple directory of images, and doodlekit doesn't store images that way.  So I figured I could just use Ajax and some Scriptaculous effects instead.  The end result is pretty slick

One thing I had to do to make it look so good is preload the next image, so you can't see it loading when the last one is fading.  To do this I have a temporary div that sits over the main image div.  I copy image A into the temp div, load image B in the main div, then fade the temp div.  This requires me to use four different timers for various purposes to make everything look smooth.
 
However, I ran into a problem when I added the previous and next links.  When you clicked on either, it loaded the proper image fine but the timers where still running.  This started a chain reaction of all kinds of crap.  

I needed a way to stop the timers, but I was using Rail's Javascript helpers which meant I couldn't just get the timer's id and call clearTimeout.

Instead I came up with a cool way to clear all the timers in one swoop.  Basically I override the setTimeout method and store each timer id in an array.  Then when I need to I just loop through the array and clear them all.

    timers = new Array();
    oldSetTimeout = window.setTimeout;
    window.setTimeout = function(code, interval) {
      timers.push(oldSetTimeout(code, interval));
    }
    
    function resetTimeouts() {
      timers = new Array();
    }
    
    function clearTimeouts() {
      for (var i= 0;i < timers.length; i++) {
        clearTimeout(timers[i]);
      }
      resetTimeouts();
    }


I know this isn't totally elegant, but I think it's a good solution to a sticky problem.  To use, just include this code and call clearTimeouts whenever you want.  I extracted resetTimeouts so it could be called after each slide transition, and so the timer array didn't just keep growing.
 

Tags: Rails, javascript, doodlekit, ajax, scriptaculous

 Comments

 Stephen Ausman  06/05/2007 03:58AM 

Slideshow feature is awesome :)

Can't wait to see what you make next.

 rheaghen  06/11/2007 03:08PM 

pretty slick ben. =)

 rheaghen  07/02/2007 10:45PM 

Hey, it would also be pretty cool if the next, previous links also used the fade effect.

 Ben Kittrell  07/03/2007 12:27AM 

Yeah, I wanted to, but the timing is already pretty complicated and volatile. I might try that later.

 Jon My Website  04/04/2010 02:16AM 

Awesome little function, nice work!

 MAC makeup wholesale My Website  10/07/2010 05:13PM 

Have a nice day for you!

 yiwu My Website  10/11/2010 05:20AM 

Awesome little function, nice work!

 swarovski jewellery sale My Website  10/21/2010 06:41AM 

we like<a href="http://www.swarovski-crystal-jewelry.net"><strong>swarovski jewellery< /strong></a>
and I always buy <a href="http://www.swarovski-crystal-jewelry.net"><strong>swarovski jewelry< /strong></a>
they have good quality <a href="http://www.swarovski-crystal-jewelry.net/swarovski-necklace-c-5.html"><strong>swarovski necklace/strong></a>

 st laurent florist My Website  12/08/2010 05:05PM 

It's good javascript. I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day!

 Foakleys My Website  02/12/2012 03:50PM 

Those who know better than the good of those who, not the music, Good question, is good. And if they do not want to, just casually ask, that is able to get the correct answer,

 Agnes My Website  05/10/2013 03:03AM 

Quite an excellent page you've shared in here. Impressive in here indeed. thanks for sharing.. http://www.goldceo.com/NeverWinter/NeverWinter-gold.shtml

 Rachael  05/10/2013 03:02AM 

Very good points you wrote here..Great stuffI think youve made some truly interesting points.Keep up the good work http://www.wtssb.com/gold.html

 Paige My Website  05/10/2013 03:04AM 

Good!This post is creative,you'll find a lot of new idea,it gives me inspiration.I believe I will also inspired by you and feel about extra new ideas.thanks http://shaiyagoldsell.com/gold.html

 Ana My Website  05/10/2013 03:06AM 

Everyday is an interesting new life adventure. Impressive indeed. thanks http://www.finshoes.com/

 Ruby My Website  05/10/2013 11:38AM 

Very interesting discussion glad that I came across such informative post. Keep up the good work friend. Glad to be part of your net community. http://youtu.be/NzhWv7IL-bk

 Juli  02/19/2015 01:42PM 

Brillaint work with awesome events conducting. Happy to see your last event and appreciating audience.
http://www.phillywedding.org

 binggo  02/28/2015 03:10AM 

Good!This post is creative,you'll find a lot of new idea,it gives me inspiration.I believe I will also inspired by you and feel about extra new ideas.thanks
http://buletinresep.blogspot.com/

 these details My Website  03/01/2015 04:25AM 

Thank you for the hard work you have made in writing this post. In the future I am hopeful the same best work from you as well. Actually your creative writing abilities has motivated me

 verhuisbedrijf zoetermeer My Website  03/03/2015 11:16AM 

This is such a great post, and was thinking much the same myself. Another great update.

 Amy  03/05/2015 01:11PM 

Interesting and amazing how your post is! It Is Useful and helpful for me That I like it very much, and I am looking forward to Hearing from your next..
http://www.nhbensautobody.com

 Nimi  03/07/2015 01:33PM 

This is very interesting news website running 24 hours a day to keep their viewer updated all the time. 
http://www.sddollhouse.com

 gemmes  03/28/2015 05:18PM 

This is very interesting news website running 24 hours a day to keep their viewer updated all the time. gemmes gratuit http://astucesaclashofclans.fr/astucesclashofclans.html

 Wholesale  03/29/2015 03:10PM 

This is very interesting news website running 24 hours a day to keep their viewer updated all the time. Wholesale Gemstone online http://www.lonzejewelry.com

 Loren  03/31/2015 08:57AM 

You’ve written nice post, I am gonna bookmark this page, thanks for info. I actually appreciate your own position and I will be sure to come back here.
http://www.robhuff.co.uk

 Sandy  04/02/2015 02:21PM 

I would like to thank you for the efforts you have made in writing this post.
http://www.mytzweb.co.uk

 dubstep  04/07/2015 11:15AM 

Thank you your page is very valuable for me. I really feel really delighted when found your page..!! new dubstep 2015 http://www.youtube.com/watch?v=XTK4gAkQPuk

 driving  04/16/2015 03:48PM 

I am really impressed with your work here today. I think you've highlighted each aspect of this topic clearly and I love that. I hope to see more of this same stuff! driving school http://www.intensivedrivingcourse.info/crashcourseblackpool.html

 pradanin My Website  04/21/2015 12:08PM 

Thank you for sharing this interesting information .. I will keep visiting this web course with the latest information from you ..

http://indomotif.weebly.com/
http://situsmotor.blog.com/

 Chip  05/03/2015 02:24PM 

Your blog! What should I say in its praise… relevant, lastly something which surely helped me? Thanks Chip Eng Seng Condo http://www.highparkresidences-condo.com

 keukenwerkblad My Website  05/15/2015 04:46PM 

I don't be sorry that spent a few of minutes for reading. Write more often, surely’ll come to read amazing new.

 Emma  05/18/2015 10:27AM 

I've been waiting for someone to share these articles. It really makes me think that I want to read more.On this subject, thank you very much to write such an interesting article.mty
http://www.camden-sc.com

 VENUS  05/18/2015 08:44PM 

Thank you. VENUS FACTOR REVIEWS http://thevenusfactorreviewsx.com/

 Amy  05/19/2015 09:58AM 

Fantastic post however I was wanting to know if you could write a litte more on this subject? I'd be very thankful if you could elaborate a little bit more. Cheers!
http://www.resourcesworkforce.com

 train accident lawyer My Website  05/22/2015 06:26PM 

This is also a very good post which I really enjoyed reading. Thanks for the share and keep more post coming!

 sadaqat  05/30/2015 11:53PM 

The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface. https://www.luckies.co.uk/gifts/fathers-day/

 graniet tafelblad My Website  06/07/2015 08:43AM 

I acknowledge the same best work from you at some point or an alternate later.

 harga ponsel baru My Website  08/12/2015 06:56AM 

Thank you for your post, I have found it here, this post gives me a lot of benefits.

 gibran My Website  09/24/2015 06:50PM 

Thank you for your post, I like your post and all that you share with us up to date and quite informative, I would like to bookmark a page so I can come here again to read your latest article. <a href="http://semaphone.weebly.com/ ">semaphone</a>

 Diaphone My Website  10/15/2015 11:32AM 

articles of interest .. I would always wait for other interesting articles from you .. thank you for sharing.
https://jipani.wordpress.com/

 psd to email My Website  11/15/2015 09:23AM 

It's good javascript. I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day!

 Arena Gadget My Website  11/17/2015 11:39AM 

very interesting to learn .. thank you for sharing your article ..

 http://marmeren-werkbladen.nl My Website  12/13/2015 10:58AM 

Here is the worthy reading articles I have to recommend to you. You would earn much useful information like me.

 marmeren keukentablet My Website  12/29/2015 11:48AM 

All the contents you mentioned in post are too good and can be very useful. Thanks for sharing the information keep updating, looking forward for more posts.

 This website My Website  12/29/2015 06:15PM 

Very efficiently written information. It will be priceless to anybody who uses it, together with myself. Sustain the good work for positive.
<a href="http://marmeren-werkbladen.nl">marmeren werkblad</a>

 selbstklebende bh My Website  02/19/2016 06:00AM 

Very interesting points you have observed, appreciate it for putting up.

 Riandika My Website  04/09/2016 10:16AM 

nice .. thanks for sharing

http://subaliadi.weebly.com/

 Mardi My Website  04/28/2016 12:12PM 

Thank you for this interesting article, this post has great significance for me, it just makes me do things better life. success is always for you ..

http://arenagadget.heck.in/
http://baloktechno.blogspot.co.id/

 visit KingSuplemen.com My Website  05/25/2016 09:17AM 

This blog is great i love reading your posts. Keep up the great work! You know, a lot of people are hunting around for this info, you could help them greatly

 Restaurantsnearmenow.org My Website  06/29/2016 01:57PM 

valuable, and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offering such a helpful information here.

 english titles My Website  07/02/2016 01:34PM 

You will be expected to take care of the daily cleaning of the yacht. This ranges from the guest’s bedrooms right up to the deck. So that the entire yacht is spotless and the decorations are polished,

 Previous 1 2 Next 

 Post a Comment



 Search

Follow On...

  • Facebook
  • Twitter
  • LinkedIn
  • Google+
  • Pinterest
  • RSS Feeds
  • Blog Posts,
  • Blog Comments,
  • Gallery Images,
  • Forum Topics

Copyright © 2006 Garbage Burrito. All Rights Reserved.
hosted by doodlekit™- free website builder

 

 powered by Doodlekit™ Free Website Builder