views:

201

answers:

1

Hey everyone.

I'm creating a simple 3-image slide show, and I'm pretty new to Jquery and Cycle. I have the slideshow working, with 3 pager links that also work.

The only thing I need to accomplish is, add "activeSlide" functionality to the currently selected pager image, which I can't do in CSS by simply using the activeSlide class...because I want to change the active pager's image source...while if it were just simple text numbers by default, I would style the activeSlide class.

Essentially, I want to swap test-select-off.jpg with test-select-on.jpg when that active slide pager is reached.

Cycle code:

$(function() {
    $('#testimonial-features').cycle({  
        speed: 800,
            timeout: '6500',
            pause: 'true',
            pager: '#testimonial-switcher',
            pagerAnchorBuilder: function(idx, slide) { 
             return '#testimonial-switcher li:eq(' + idx + ') a';       
            } 
    });
});

HTML code:

<div id="testimonial-switcher">
<ul>
    <li><a href="#"><img src="images/layout/test-select-off.jpg" /></a></li>
    <li><a href="#"><img src="images/layout/test-select-off.jpg" /></a></li>
    <li><a href="#"><img src="images/layout/test-select-off.jpg" /></a></li>
</ul>

How can I do this? I assume I'd need to do something in the updateActivePagerLink option by modifying the updateActivePagerLink function, taken from http://www.malsup.com/jquery/cycle/pager7.html:

$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
    $(pager).find('li').removeClass('activeLI') 
        .filter('li:eq('+currSlideIndex+')').addClass('activeLI'); 
}; 

but like I said, i'm still learning this syntax, so any help would be greatly appreciated!

A: 

EDIT: Apparently, since I wasn't familiar with the plugin, my original answer didn't work. However, since you found something that partially does, I'll update the answer here with a solution that should work completely. All you have to do in addition to what you found is at the beginning of that function change them all to 'off' (line 1), then change the active one to 'on' (what you added).

$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
    $(pager).find('img').attr('src','images/layout/test-select-on.jpg');
    $(pager).find('li').removeClass('activeLI') 
            .filter('li:eq('+currSlideIndex+')').addClass('activeLI')
            .find('img').attr('src','images/layout/test-select-on.jpg'); 
};

Let me know if that works.


Original wrong answer (leaving it in so the comments make sense)
It looks like you can replace the src of the img within whichever li has the class .activeLI inside the after callback function (though I haven't used the Cycle plugin before and am just gleaning that last bit from the docs).

So change the Cycle code to:

$(function() {
    $('#testimonial-features').cycle({  
        speed: 800,
        timeout: '6500',
        pause: 'true',
        pager: '#testimonial-switcher',
        pagerAnchorBuilder: function(idx, slide) { 
         return '#testimonial-switcher li:eq(' + idx + ') a';       
        },
        after: function(curr, next, opts) {
         $(curr).find('img').attr('src','images/layout/test-select-on.jpg');
        } 
    });
});

And let me know if that works! (Note: if this doesn't work try unwrapping the $() from the curr in the after: function()... like I said, haven't used this plugin before)

mVChr
Thanks for the response...I tried the code, and it doesn't seem to do anything. I changed $(curr) to curr, and it breaks it, causing it to not cycle at all.
Andrew Parisi
Nevermind, that was stupidly simple: $.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { $(pager).find('li').removeClass('activeItem').addClass('inactiveItem').filter('li:eq('+currSlideIndex+')').removeClass('inactiveItem').addClass('activeItem'); $('.inactiveItem').find('img').attr('src','images/layout/test-select-off.jpg'); $('.activeItem').find('img').attr('src','images/layout/test-select-on.jpg'); };
Andrew Parisi
@Andrew-Parisi I edited my answer with a solution that should work. Let me know. EDIT: oops, you beat me to it.
mVChr