Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple carousels (carouFredSel) using jquery each, link identifier issue

I'm using the following code to create multiple slidehows on 1 page.

The slideshows work fine, but I can't get the individual buttons of each slideshow to work. When I click them the page just scrolls to the top. I thought by uniquely identifying each link I shouldn't have a problem.

Any ideas what's wrong?

        $("div.slideshow").each(function(){
            $(this).find('ul').carouFredSel
            ({
            auto:true,
             items: { width: 200, height: 200 },
             prev: { button: function() { return $(this).find('a.prev');}},             
             next: { button: function() { return $(this).find('a.next'); }},          
            });
    console.log( $(this).find('a.prev') ); //correct element returned, length 1
    console.log($(this));  //correct element returned
    });
like image 282
rix Avatar asked Mar 01 '13 11:03

rix


2 Answers

if code next

<div class="image_carousel">
    <div class="sec_elem">
        <div class="tem-bl">
            <img src="image.jpg" alt=""/>
        </div>
        <div class="tem-bl">
            <img src="image.jpg" alt=""/>
        </div>
        <div class="tem-bl">
            <img src="image.jpg" alt=""/>
        </div>
    </div>

    <a class="prev" href="#"></a>
    <a class="next" href="#"></a>
</div>

jquery

$(".sec_elem").carouFredSel({
    circular: true,
    infinite: false,
    width:'100%',
    auto    : true,
    scroll  : {
        items   : 1,
        pauseOnHover    : true,
        duration    : 1000
    },
    prev    : {
        button  : function(){
            return $(this).parents('.image_carousel').find('.prev');
        },
        key     : "left"
    },
    next    : {
        button  : function(){
            return $(this).parents('.image_carousel').find('.next');
        },
        key     : "right"
    }
});
like image 97
tauruz Avatar answered Sep 17 '22 14:09

tauruz


Since the page scrolls to the top, the problem is with carouFredSel initializing the pagers at all. Very likely an issue with your markup.

I've also had some odd issues with using the responsive : true option, along the lines you just described.

I've created a jsFiddle to show a working example of pagination with multiple carousels in a jQuery tabs UI:

http://jsfiddle.net/EFC3X/

like image 43
Zachary Schuessler Avatar answered Sep 19 '22 14:09

Zachary Schuessler