JavaScript slideshow fun

February 22, 2006 at 12:48 am | In javascript, tech | 23 Comments

There are things that go smoothly, run like a dream and never complain; there are others that don’t. For me, debugging JavaScript is always one the latter.

DHTML UtopiaI have only recently begun to appreciate the power and fun to be had hacking at javascript, I used to panic at the thought of it. This was until I joined Torchbox where I received not only the help and confidence boost I needed, but also the office has a copy of Stuart’s book ‘DHTML Utopia‘.

I have only gone through the first three or so chapters in detail but over the past six months I have learnt to love event listeners and writing JavaScript as a seamless behaviour layer. No more do I panic about getting tangled up in ‘onclick’s and ‘JavaScript:‘ – things become easier and a lot more fun when you can abstract the JavaScript from the page entirely.

I have written one or two snippets that I am quite pleased with, and although I have learnt to love writing JavaScript, I still hate debugging it. My most recent exploit has been into the realm of an accessible slideshow.

For work we wanted a way of showing images as a funky slideshow, the slideshow however needed to change the URL for each image and have the ability for the user to either manually alter the URL to go to an image, use the browser’s back button and bookmark an image. The user should choose when to move to another image so in the previously mentioned situations and when next or previous is clicked the images should fade into the next.

In true 2.0 style I have a beta‘ version up and running, its not yet there but its a start. The next and previous links work and fade nicely, the back button really does work (even with the fade) as does the ability to change the URL manually. All images used are ones I have taken and are licensed under the creative commons.

The final version will:

  • Fix all the bugs – so the style ‘issues’, (mainly in IE) there is a flash of the previous image in Safari and some nightmarish debugging is needed for the ‘Permission denied’ error I am getting in IE6! (You may have already guessed that I unashamedly developed this in FireFox.)
  • Fix the performance problem – I really don’t know why this occurs but if you click through a number of images by the time you get to 6 or 7 the performance lag is very noticeable. Currently, I am changing the URL with fragment ID’s from the location.hash property and updating the location.href with the id of the current image. Listening to the URL is done through a function on setInterval() on 500ms that checks against one of the few global variables if the location.hash has changed. I’m thinking of changing this to use setTimeout() instead so I can stop it during the fade and start up again straight after, this might work.
  • Have ‘further information’ links – per image that then changes (not necessarily fades) as the images do
  • Use image maps - As this was the original intention of the slideshow, to work with images that are image maps, I am really hoping that this is going to be a nice easy stage; I have yet to try setting the opacity on image maps.
  • Stress test it! - The fun part, its the fixing afterward that might not be quite such a laugh.

Some inspiration for the slideshow came from Matthew Westcott who developed the cool main image fade on http://breakthrough.org.uk/ and from the Image Cross Fader Redux.

Feel free to view my efforts:

23 Comments »

RSS feed for comments on this post. TrackBack URI

  1. Also consider putting a prev/next link set at the top, where it’s fixed location will make it easier to repeatedly click the same link without re-mousing.

    … And the long load time before reorging the page into the slideshow onload may be confusing. I can imagine people thinking its a regular list of photos, scrolling down (as it continues to load) and then being surprised when the page pops down to the first image.

    Two ways I can think of to address that:

    1) Don’t wait for onload to start scripting: you could immediately start watching for img elms (even as the doc is being loaded) and hide them as they are parsed into the DOM.

    2) From script, immediately style all images to be hidden, then onload fix up your viewer and un-hide them.

    … I think the 2nd way is better. In the 1st way, you’re likely to be fighting rendering reflows with the first approach.

    (Sorry for the criticism– I do like the general result. :))

  2. Thanks Jeremy that’s really useful. The second method, like you said, does sound a cleaner way of approaching the solution – Ill have a go at that :)

  3. Nice. I like that. As an alternative to Jeremy’s suggestions, you might want to hook DOMContentLoaded (in Firefox) and use Dean’s defer trick (http://dean.edwards.name/weblog/2005/09/busted/) in IE so you don’t hang while the images are loading.

    And thanks for the book pimpage, although you of course know that the technical editor did all the *hard* work. :-)

  4. [...] As pointed out by Jeremy, my linkable slideshow needed some work to fix the load order of the page without altering the ‘unobtrusiveness’ of its behaviour. [...]

  5. Hey Stuart– what’s with the frog cover? The one’s I’ve bought (2) both have the hang glider…

  6. I did look at using DOMContentLoaded and Dean’s defer trick but the solution I came up with worked so the slideshow no-longer hangs while the images load, I will probably go back and use that trick anyway though, I just wanted to see if the try / catch on the DOM loading worked as a quick fix for the time being. Thanks for the suggestion … and the book! and I much prefer the frog cover :)

  7. Frog cover…your guess is as good as mine. The covers happen somewhere I don’t know about. :)

  8. Nat, just jumped here from Simon’s site ;) – if you’re looking to get fancy with listeners, definitely check out the Y! util.Event stuff.

    Stuart, the hang Glider was much cooler. at least you don’t have a funny pop-up-clown-box like Cameron’s book. Some of these covers just trip me out – you really have to question what they were thinking.

  9. [...] Cosillas de JavaScript, DHTML, DOMScripting o cómo se le quiera llamar… Un fundido de imágenes, otro y un tercero. DOMTab son unas pestañas bastante apañadas, justo igual que JavaScript Tabifier. [...]

  10. wedding cake flowers

  11. brunette teens

    Idinax33000i

  12. interracial porno

    cr00topcheg

  13. first masturbation

    Idinax33000i

  14. nude woman

    cr00topcheg

  15. naked and mature women

    cr00topcheg

  16. lesbian bdsm bdsm comics

    zd00linkar

  17. cock sucking monsters of cock

    privegfd000g

  18. asian teens asian schoolgirl porn

    polezsukablya000

  19. fat guy sex

    n00stalgie

  20. http://www.google.com

  21. http://www.google.com

  22. history of airsoft

    Blog Records:the medicine neurotinComments…

  23. Here, Check This Out, Pretty GoodHave you seen my site? AMAZING,


Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.