There are a lot of carousels on the page (they symbolize purchases), each element of the carousel is clickable and causes a sliding block with information under this carousel (I made this block alone, the information in it will be loaded using AJAX, why is it alone? - because it is in carousel wrapper, because its height is fixed because of the animation during the hover, and I need to move the block apart pushing all the others).

I managed to isolate the merry-go-rounds separately, there was nothing complicated here.

  1. Now it’s necessary to transfer the activity class inside the carousel itself, I know that the solution is simple, but I cannot reach it myself.
  2. Inside the most expanding block appeared

My js for this:

$(document).ready(function () { var active = 'carousel-flights-item--active'; //element-carousel $('.js-flights-info-trigger').click(function(){ if ($(this).hasClass(active)) { $(this).removeClass(active); $(this).parents().children('.js-flights-info-slide').slideToggle(); } else { $(this).addClass(active); $(this).parents().children('.js-flights-info-slide').slideToggle(); } } ); //inside $('.js-flights-info-trigger-slide-up').click(function(){ if ($(this).parents().children('.carousel-flights-item').hasClass(active)) { $(this).parents().children('.carousel-flights-item').removeClass(active); $(this).parents().children('.js-flights-info-slide').slideToggle(); } else { $(this).parents().children('.carousel-flights-item').addClass(active); $(this).parents().children('.js-flights-info-slide').slideToggle(); } } ); }); 

Waiting for help, thanks in advance! If the solution is not elegant, offer another!

    1 answer 1

     $(document).ready(function () { var active = 'carousel-flights-item--active'; var $triggerItems = $('.js-flights-info-trigger'); var $infoSlideItems = $('.js-flights-info-slide'); //element-carousel $triggerItems.click(function(){ var isActive = $(this).hasClass(active); $triggerItems.removeClass(active); $infoSlideItems.slideUp(); if (!isActive) { $(this).addClass(active) .parents().children('.js-flights-info-slide') .stop(true, false) .slideDown(); } }); }); 

    I hope I understand your task correctly. I only changed the $(document).ready block in js.

    • I think today I will arrange it all on jsfiddle, as I get to the computer. - Jarvis
    • Laid on codepen codepen.io/anon/pen/bpjbBK - Jarvis
    • Corrected your answer. - Pleshevskiy