views:

250

answers:

4

The request is a simple one, but is hard to google for. Here are the requirements:

  • I have a JS array with image urls
  • I dont have any backing html
  • I want a decent slideshow plugin to consume this array and give me a slideshow
  • The slideshow supports using keyboard navigation (bonus)

So far, ive seen lots of slideshow plugins that require lots of complex backing html, and css. it seems somewhat silly to construct this html in order for it to be transformed by the slideshow plugin anyway.

Also, i had no idea how bad some of the code behind these slideshow plugins can be. jeez!

A: 

Go through some of the past articles / items on http://www.designfloat.com/ - there are quite a few excellent jQuery samples of what you are trying to do.

Regards,

Rene Pilon

+1  A: 

Dunno about keyboard navigation, but the answer I accepted to this similar question should sort you out.

EDIT: Just realised it also includes keyboard navigation. See how I implemented it for reference if you like (click the folio tab).

da5id
+3  A: 

Here is something I quickly put together (haven't tested it at all - it's just for ideas) that you might be able to develop on. It shouldn't be hard.

var imgs = ['a.png', 'b.png', 'c.png'];

function Slideshow(img_list, container) {
    var self = this;
    var $slides = [];
    var current = { 'ith': 0, '$slide': null };

    function initialize() {
        // Create the images
        img_list.map(function (i) {
            $slides.push($('<img>').attr('src', i).hide().appendTo(container));
        });     

        current.$slide = $slides[0];
        current.ith = 0;

        // Initialize binds (jquery hotkeys or something)
        $(document).bind('keydown', '>', function () {
            // Do stuff
            self.next();
        });

        $(document).bind('keydown', '<', function () {
            // Do stuff
            self.prev();
        });

    };

    this.indexTo = function (i) {
        current.$slide.hide();
        current.$slide = $slides[i];
        current.ith = i;

        if (current.$slide ==== undefined) {
            if (i < 0) {
                current.$slide = $slides[$slides.length - 1];
                current.ith = $slides.length - 1;
            } else {
                current.$slide = $slides[0];
                current.ith = 0;
            }
        }

        // Effects or something else
        return current.$slide.show();
    };

    this.next = function () {
        return self.indexTo(current.ith++);
    };

    this.prev = function () {
        return self.indexTo(current.ith--);
    };

    initialize();
};
Justin Van Horne
Wow. Way to go above and beyond.
Andy Gaskell
I doubt it is really practical, but I was just trying to spark some motivation - It's good to learn this stuff and understand structure and completeness rather than just assume that plugins are the right route. I have seen countless __horrible__ plugins.He just needs to evaluate the problem and address what he needs. If it is too complex, then jQuery Cycle may be his best bet, otherwise, it would be a good experience to build it himself.Best of luck.
Justin Van Horne
Hey, thanks for writing that. the code is good! and whats more, its going to be easy to build on as i need more stuff. Thanks a lot. ill send some rep your way
mkoryak
A: 

This jQuery plugin called Cycle is one of the nicest slideshows I've seen (that isn't a lightbox type). I looked through the documents and it doesn't seem to have keyboard support nor an option to use an array for the images, but it does have examples of dynamically adding more images. Anyway, judge for yourself.

fudgey