rix
rix

Reputation: 10632

Advice on making a responsive jquery carousel with images overflowing vertically

I'm making a carousel from the html structure shown below. There are actually about 40 images.

<div id="carousel">
    <div class="pris"><img src=""/></div>
    <div class="pris"><img src=""/></div>
    <div class="pris"><img src=""/></div>
    <div class="pris"><img src=""/></div>
    <div class="pris"><img src=""/></div>
    <div class="pris"><img src=""/></div>
</div>

How can I do this, given that the first class is always in the top left of the container so when it is hidden/shown it will always appear in that area rather than passing through the container horizontally as the divs in the lower levels do.

In short, how to make a carousel when images aren't container in a long, 1 image high, horizontal line?

Edit - I don't know why people are asking to close this question. It's quite clear: is it possible to make a carousel from a div of images which are stacked vertically and not horizontally as is usually the case with carousels.

Edit (some test code) which works ok when cycling through but not when it comes back to the beginnig.

The right arrow:

$('#arrow_right a').click(function(e) {
var current = $('#pris').find('div.current');
var next = (current.next('.pris').length) ? current.next('.pris') :  $("div.pris:first");
current.removeClass('current');
current.hide();
next.addClass('current');
next.show();
show_next(getVisible());
e.preventDefault();
});

function show_next(no_visible)
{
current = $('#carousel').find('div.current');
 next_one = (current.next('.pris').length) ? current.next('.pris') : $("div.pris:first");
 next_two = (next_one.next('.pris').length) ? next_one.next('.pris') : $("div.pris:first");
 next_three = (next_two.next('.pris').length) ? next_two.next('.pris') : $("div.pris:first");

  switch(no_visible)
    {
    case 4:
    next_one.show();
    next_two.show();
    next_three.show();
    break;
    case 3:
    next_one.show();
    next_two.show();
    break;
    case 2:
    next_one.show();
    break;
    }
}

Upvotes: 1

Views: 537

Answers (1)

Roko C. Buljan
Roko C. Buljan

Reputation: 206008

Yes, it's possible.
You want to animate vertically, right? Given the tip that it's about responsive design, you need to calculate on window load/+/resize the height of one image (or container height) and animate respectively your carousel scrollTop property (given the fact it's an overflow hidden element.)

Upvotes: 1

Related Questions