jsor / jcarousel

Riding carousels with jQuery.
https://sorgalla.com/jcarousel/
MIT License
1.99k stars 734 forks source link

Background change #771

Closed lpguedes closed 9 years ago

lpguedes commented 9 years ago

Hi!

It's possible to change the background image (or some div background) when the image of the carousel changes?

My objective is use a specific background to a specific image in the carousel, and when the image change in carousel, the background changes too.

I found the _animate function and configured to return an alert message when the routine pass that way. At the same time I inserted an attribute called data-bg-image in the li tag, and this attribute is the path to the background I need to show.

Is there any way to do that?

Thanks!

jsor commented 9 years ago

Yes, you can use the targetin item event:

$('.jcarousel').on('jcarousel:targetin', 'li', function() {
    var bgImage = $(this).data('bg-image');
    // Do something with bgImage
});
lpguedes commented 9 years ago

Thank you, jsor!