Search code examples
jqueryjquery-cycle2

get image source of current slide in cycle2 slider


I'm trying to get the source of the current image in an installation of Cycle2 to pass to an addThis photo sharing script

here is what I have been able to figure out from the Cycle2 API:

$('.cycle-slideshow').on('cycle-after', function (e, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
    var imgSrc = $(outgoingSlideEl).attr('src');
});

If I'm missing anything, please advise.


Solution

  • I think your outgoingSlideEl is an list element like li

    Then you should use find() to find your image src like,

    var imgSrc = $(outgoingSlideEl).find('img').attr('src');
    

    Full Code

    $('.cycle-slideshow').on('cycle-after', function(e, optionHash, outgoingSlideEl,
                                                      incomingSlideEl, forwardFlag) {
        var imgSrc = $(outgoingSlideEl).find('img').attr('src');
    });
    

    Live Demo