15

i want to highlight current item , how do i get the image source and current thumbnail ? http://jsfiddle.net/RL8MV/2/

$('#carousel span').append('<img src="http://coolcarousels.frebsite.nl/c/28/img/gui/carousel_glare.png" class="glare" />');
                $('#thumbs a').append('<img src="http://coolcarousels.frebsite.nl/c/28/img/gui/carousel_glare_small.png" class="glare" />');

                $('#carousel').carouFredSel({
                    responsive: true,
                    circular: false,
                    auto: true,
                    items: {
                        visible: 1,
                        width: 200,
                        height: '56%'
                    },
                    scroll: {
                        fx: 'directscroll'
                    }
                });

                $('#thumbs').carouFredSel({
                    responsive: true,
                    circular: true,
                    infinite: true,
                    auto: {
                        play:true
                    },
                    scroll:
                    {
                        items: 1,
                        onBefore: function() {

                            var pos = $("#thumbs").triggerHandler("currentPosition");
                           // alert( "The carousel is at item number " + pos );


                        }

                    },
                    prev: '#prev',
                    next: '#next',
                    items: {
                        visible: {
                            min: 2,
                            max: 6
                        },
                        width: 150,
                        height: '66%'
                    }
                });

                $('#thumbs a').click(function() {
                    $('#carousel').trigger('slideTo', '#' + this.href.split('#').pop() );
                    $('#thumbs a').removeClass('selected');
                    $(this).addClass('selected');
                    return false;
                });​
Parag
  • 4,445
  • 9
  • 30
  • 49

2 Answers2

10

Finally got it solved :)

http://jsfiddle.net/RL8MV/5/

function highlight( items ) {
                items.filter(":eq(0)").css({
                    backgroundColor: "#ff9",
                    width    : 140,
                    height    : 100,
                    margin    : 7
                });
                return items;
            }
            function unhighlight( items ) {
                items.css({
                    backgroundColor: "#fff",

                    margin    : 27
                });
                return items;
            }



$('#carousel span').append('<img src="http://coolcarousels.frebsite.nl/c/28/img/gui/carousel_glare.png" class="glare" />');
                $('#thumbs a').append('<img src="http://coolcarousels.frebsite.nl/c/28/img/gui/carousel_glare_small.png" class="glare" />');


                $('#carousel').carouFredSel({
                    responsive: false,
                    circular: false,
                    auto: false,
                    items: {
                        visible: 1,
                        width: 540,
                        height: '56%'
                    },
                    scroll: {
                        fx: 'directscroll'
                    }
                });

                $('#thumbs').carouFredSel({
                    responsive: true,
                    circular: true,
                    infinite: true,




                    auto: {
                                play:true,
                                onBefore: function( data ) {
                                    unhighlight( data.items.old );
                                },
                                onBefore    : function( data ) {
                                    highlight( data.items.visible );


                                    $('#carousel').trigger('slideTo', '#' + data.items.visible.eq(0).attr("id").split('_').pop() );
                                    $('#thumbs img').removeClass('selected');
                                    $("#curimg").html(data.items.visible.eq(0).attr("id").split('_').pop());
                                    //$(this).addClass('selected');
                                }
                    },

                    scroll:
                    {
                        items: 1,

                    },
                    prev: 
                    {
                        button:'#prev',
                        onAfter: function( data ) {
                                    unhighlight( data.items.old );
                                },
                                onBefore    : function( data ) {
                                    highlight( data.items.visible );

                                    $("#curimg").html(data.items.visible.eq(0).attr("id").split('_').pop());
                                    $('#carousel').trigger('slideTo', '#' + data.items.visible.eq(0).attr("id").split('_').pop() );
                                    $('#thumbs img').removeClass('selected');
                                    $("#curimg").html(data.items.visible.eq(0).attr("id").split('_').pop());
                                    //$(this).addClass('selected');
                                }
                    },
                    next:
                    {
                        button:'#next',
                        onAfter: function( data ) {
                                    unhighlight( data.items.old );
                                },
                                onBefore    : function( data ) {
                                    highlight( data.items.visible );

                                    $("#curimg").html(data.items.visible.eq(0).attr("id").split('_').pop());
                                    $('#carousel').trigger('slideTo', '#' + data.items.visible.eq(0).attr("id").split('_').pop() );
                                    $('#thumbs img').removeClass('selected');
                                    $("#curimg").html(data.items.visible.eq(0).attr("id").split('_').pop());
                                    //$(this).addClass('selected');
                                }
                    },
                    items: {
                        visible: {
                            min: 2,
                            max: 6
                        },
                        width: 150,
                        height: '66%'
                    }
                });

                $('#thumbs img').click(function() {
                    $('#carousel').trigger('slideTo', '#' + this.id.split('_').pop() );    
                    $("#curimg").html( this.id.split('_').pop());
                    $('#thumbs').trigger('slideTo', '#' + this.id);
                    $('#thumbs img').removeClass('selected');
                    $(this).addClass('selected');

                    return false;
                });​

Updated link here

Updated link for odd no of visible items to highlight middle one

Parag
  • 4,445
  • 9
  • 30
  • 49
4

You can get the source of the image by the adding the following:

var src = $(this).children('img').attr('src');

$('#thumbs a').click(function() {
  var src = $(this).children('img').attr('src'); 

  $('#carousel').trigger('slideTo', '#' + this.href.split('#').pop() );
  $('#thumbs a').removeClass('selected');
  $(this).addClass('selected');
  return false;
});​

You would do the same thing for the current thumbnail, you would just call the 'src' attr on the thumbnail holder

Menztrual
  • 37,509
  • 11
  • 55
  • 68
  • thanks for reply ; I wanted to highlight and load the current position image on scroll event and not on click of thumbnail ; $(this).children('img').attr('src') gives undefined value – Parag Dec 12 '12 at 08:20
  • 1
    `$(this).children('img')` returns a collection. Even though jQuery selects the first child for you when calling `.attr('src')`, it's not a very clean way to do so. – Robin van Baalen Dec 17 '12 at 13:04