JQuery - jCarousel - FadeIn

I use the jCarousel plugin ( http://sorgalla.com/projects/jcarousel/ ), and instead of the image slides (as in the "Autoscroll Carousel" demo)

I would like the images to fade. Usage is jCarousel, which automatically scrolls and displays only one item at a time. But I looked at the Cycle plugin, but it did not work with my script, because the element I want to show contains text and an image.

Thanks if anyone can help with this.

Phil

+3
source share
6 answers

Cycle . " " , , .

0

, jCarousel :

$('#yourContainer').jcarousel({
    visible: 1,
    scroll: 1, 
    itemLoadCallback: {
        onBeforeAnimation: mycarousel_fadeOut,
        onAfterAnimation: mycarousel_fadeIn
    }
});

function mycarousel_fadeOut(carousel) {
    var JCcontainerID = carousel.clip.context.id;
    $('#' + JCcontainerID).fadeOut();
}

function mycarousel_fadeIn(carousel) {
    var JCcontainerID = carousel.clip.context.id;
    $('#' + JCcontainerID).fadeIn();
}

, , , .

+6

Try the following:

var jcarousel = $('#yourContainer');

    jcarousel.jcarousel({
        animation: {
            duration: 0 // make changing image immediately
        }
    });

    // make fadeIn effect
    jcarousel.on('jcarousel:animate', function (event, carousel) {
        $(carousel._element.context).find('li').hide().fadeIn(1000);
    });
+6
source

Changing the functions for this is done, sort of (you can still see the scroll):

function mycarousel_fadeOut(carousel) { 
   var JCcontainer = carousel.clip.context; 
   $(JCcontainer).fadeOut(); 
} 

function mycarousel_fadeIn(carousel) { 
   var JCcontainer = carousel.clip.context; 
   $(JCcontainer).fadeIn(); 
} 
+2
source
var mycarousel_fadeOut = function(carousel, state) {
    if (state !== "init") {
        $(carousel.clip.context).find('img').fadeOut(800);
    }
};

var mycarousel_fadeIn = function(carousel, state) {
    if (state !== "init") {
        $(carousel.clip.context).find('img').fadeIn(800);
    }
};
+1
source

For version 0.3.x jCarousel, I went with this:

   var carousel = $('.jcarousel').jcarousel({
      list        : '.items',
      items       : '.i',
      wrap        : 'both', // for good measure
      animation: {
          duration: 0 // swap slides immediately
      }
   }).jcarouselAutoscroll({
      interval: 1000 * 5,
      target: '+=1',
      autostart: true
   });

   // fade hack
   carousel.jcarousel('items').hide();
   carousel.jcarousel('first').show();
   carousel.on('jcarousel:visiblein', function(event, carousel) {
      $(event.target).fadeIn();
   });
   carousel.on('jcarousel:visibleout', function(event, carousel) {
      $(event.target).fadeOut();
      carousel._trigger('animateend'); // the event doesn't fire when items are positioned absolutely (so autoscroll wouldn't work), fire manually
   });

some css to make it work:

   .items {height: 450px;}
   .i     {position: absolute;}
+1
source

Source: https://habr.com/ru/post/1715205/


All Articles