Scott Yu - builds stuff
Scott Yu - builds stuff

Reputation: 11763

jquery - make a simple gallery out of a bunch of DIVs

I was wondering if anyone has something simple to create a gallery from a bunch of divs. Such as

<div id=gallery>
    <div class='slide' id=1><img src='image1.png'> this is image 1</div>
    <div class='slide' id=2><img src='image1.png'> this is image 1</div>
    <div class='slide' id=3><img src='image1.png'> this is image 1</div>
    <div class='slide' id=4><img src='image1.png'> this is image 1</div>
</div>

I like to show one DIV at a time. Clicking div advances to next slide. And at the end, it loops back to the first one.

No effects, just a simple showing of one div followed by next.

Thanks Scott

UPDATE:

Okay, I decided to just write my own based on http://sixrevisions.com/tutorials/javascript_tutorial/create-a-slick-and-accessible-slideshow-using-jquery/. Anyone can make this code more tight and efficient, please add comment.

$(document).ready(function(){
  var currentPosition = 1;
  var slides = $('.slide');
  var numberOfSlides = slides.length;

  if(currentPosition==1){ $('.slide').hide(); $('#1').show()};

  // Create event listeners for .controls clicks
  $('.slide')
    .bind('click', function(){
    currentPosition = parseInt($(this).attr('id'));
    if(currentPosition == numberOfSlides) {
        $('.slide').hide(); 
        $('#1').show();
    } else {
        $('.slide').hide();
        nextPosition = parseInt(currentPosition+1);

        $('#'+nextPosition).show();
    }
  });
});

Upvotes: 2

Views: 3533

Answers (4)

Michael
Michael

Reputation: 1231

In my opinion the jQuery plugin Colorbox is the best! Very versatile and stable gallery.

http://colorpowered.com/colorbox/

Examples http://colorpowered.com/colorbox/core/example1/index.html

Real world implementation: http://www.bakkerbart.nl (if you press the "bestellen" button)

Upvotes: 1

kobe
kobe

Reputation: 15835

I changed my comment as answer

http://vandelaydesign.com/blog/web-development/jquery-image-galleries/

check our implementation recently on

www.allposters.com /// there is a slider here

Upvotes: 1

Patrick Beardmore
Patrick Beardmore

Reputation: 1032

Here's a similar question that got lots of answers: Nice way to show html <DIV> elements like gallery, mooflow, lightbox etc

Upvotes: 1

Christian Joudrey
Christian Joudrey

Reputation: 3461

You might want to look at the ones suggested here to save yourself time: http://blueprintds.com/2009/01/20/top-14-jquery-photo-slideshow-gallery-plugins/

  • Christian

Upvotes: 1

Related Questions