Как сделать аккордеон из нескольких ZeroBlock в Tilda

For Companies

Sign up for a free trial account?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Why can't I login to my account?
What’s special about Desk?
Get started
Set up your account, configure support channels, customize your portal to reflect your brand and more.
How does integration works?
Configuring Automations

Set up your account, configure support channels, customize your portal to reflect your brand and more.

Как сделать аккордеон из нескольких ZeroBlock в Tilda

1
Пример состоит из 9-ти ZeroBlock
4 заголовка и 5 контент
Блоки расставлены по порядку: Заголовок-Контент-Заголовок-Контент....
Разграничение видимости создавать только блоку заголовка
2
Блокам заголовков и связанных с ними контентных блоков задали классы
uc-accord-a-1 , uc-accord-a-2 , uc-accord-a-3, uc-accord-a-4
3
Элементам, которые в блоках заголовка будут открывать контент, задали класс accord
Иконке стрелочке задали класс accord-icon
4
Добавили код на страницу, в блок Другое - Т123
Mo-ti Level Up
Видео инструкции по добавлению кода и работе с Zero Block.
Создаём заголовки и контент для аккордеона использую ZeroBlock
Фрагмент видео
Библиотека для примера

<script>
$( document ).ready(function() {
    
$(function () { 
    let liter = 'a'; //Литера для сборки
    let oneAcc = true; // Открывать по одной вкладке  false - true
    let accOpen = false; // Открытая  вкладка  false - true
    let openNum = 3; // Номер открытой вкладки
    let scroll = false; // Скролл к открытой вкладке  false - true
    
    $('.accord-icon').addClass('accord');

	$('div[class*="uc-accord-'+liter+'"]').each(function(index){
        $('.uc-accord-'+liter+'-'+index+':first').addClass('title-accord').attr('data-accord-index', index);
        $('.uc-accord-'+liter+'-'+index+'').not(':first').addClass('content-accord hide-accord');
        
	});
	
	if(accOpen){
	    $('div[class*="uc-accord-'+liter+'-'+openNum+'"]').addClass('active-accord');
	    $('div.content-accord[class*="uc-accord-'+liter+'-'+openNum+'"]').removeClass('hide-accord');  
	};
	
	setTimeout(function(){ $('.content-accord').addClass('time-step')}, 1500);

	function videoStop(){
	    setTimeout(function(){ 
	        $('div.content-accord.hide-accord[class*="uc-accord-'+liter+'-"]').each(function(){
	            let videoNum = $(this).find('div[data-elem-type="video"]').length;
	            if(videoNum){
                    $(this).find('div[data-elem-type="video"]').each(function(){
                        $(this).find('iframe').attr( 'src', function ( i, val ) { return val; });
                    });    
	            };
	        });
	    }, 300);
	};

	$('div[class*="uc-accord-'+liter+'"]').find('.accord').click(function(e){
        let cT = $(this).closest('.title-accord');
        let ind = cT.attr('data-accord-index');
        
        
        if(oneAcc){
            //По одной  вкладке
            if( cT.hasClass('active-accord') ){
                cT.removeClass('active-accord');
                $('div.content-accord.uc-accord-'+liter+'-'+ind+'').toggleClass('hide-accord');  
                videoStop();
            }else{
                $('div.title-accord[class*="uc-accord-'+liter+'"]').removeClass('active-accord');
                cT.addClass('active-accord');
                $('div.content-accord[class*="uc-accord-'+liter+'-"]').addClass('hide-accord');
                $('div.content-accord.uc-accord-'+liter+'-'+ind+'').removeClass('hide-accord');  
                videoStop();
            };
     
        }else{
            //По несколько вкладок
            cT.toggleClass('active-accord');
            $('div.content-accord.uc-accord-'+liter+'-'+ind+'').toggleClass('hide-accord');  
            videoStop();
        };
        
            if(scroll){ //скролл до вкладки
            let el = $(this).closest('.r');
            setTimeout(function(){
                $('html, body').animate({scrollTop:  el.offset().top-50   }, 400);
            }, 600);
        };

	});
    
});
      
});
</script>

<style>
.hide-accord .t396__artboard {
    height: 0!important;
    pointer-events: none!important;
    overflow: hidden!important;
}    
.content-accord.time-step .t396__artboard , .accord-icon {   transition: all 0.4s ease-in-out}    
.content-accord {
    padding-top: 0!important;
    padding-bottom: 0!important;
}
.active-accord .accord-icon {  transform: rotate(180deg)}
.accord {  cursor: pointer}
</style>
Библиотека для примера
Autoscale

<script>
$( document ).ready(function() {

$(function () {
let liter = 'a'; //Литера для сборки
let oneAcc = true; // Открывать по одной вкладке false - true
let accOpen = false; // Открытая вкладка false - true
let openNum = 3; // Номер открытой вкладки
let scroll = false; // Скролл к открытой вкладке false - true

$('.accord-icon').addClass('accord');

$('div[class*="uc-accord-'+liter+'"]').each(function(index){
        $('.uc-accord-'+liter+'-'+index+':first').addClass('title-accord').attr('data-accord-index', index);
        $('.uc-accord-'+liter+'-'+index+'').not(':first').addClass('content-accord hide-accord');
});

if(accOpen){
$('div[class*="uc-accord-'+liter+'-'+openNum+'"]').addClass('active-accord');
$('div.content-accord[class*="uc-accord-'+liter+'-'+openNum+'"]').removeClass('hide-accord');
};

function setRecHeight(){
setTimeout(function(){
$('.content-accord').each(function(){
$(this).addClass('time-step');
let hg = $(this).find('.t396__artboard').height();
$(this).height(hg);
});
}, 1500);
};

setRecHeight();

$(window).resize(function() {clearTimeout(window.resizedFinished); window.resizedFinished = setTimeout(function(){ setRecHeight() }, 300);});

function videoStop(){
setTimeout(function(){
$('div.content-accord.hide-accord[class*="uc-accord-'+liter+'-"]').each(function(){
let videoNum = $(this).find('div[data-elem-type="video"]').length;
if(videoNum){
$(this).find('div[data-elem-type="video"]').each(function(){
$(this).find('iframe').attr( 'src', function ( i, val ) { return val; });
});
};
});
}, 300);
};

$('div[class*="uc-accord-'+liter+'"]').find('.accord').click(function(e){
let cT = $(this).closest('.title-accord');
let ind = cT.attr('data-accord-index');


if(oneAcc){
//По одной вкладке
if( cT.hasClass('active-accord') ){
cT.removeClass('active-accord');
$('div.content-accord.uc-accord-'+liter+'-'+ind+'').toggleClass('hide-accord');
videoStop();
}else{
$('div.title-accord[class*="uc-accord-'+liter+'"]').removeClass('active-accord');
cT.addClass('active-accord');
$('div.content-accord[class*="uc-accord-'+liter+'-"]').addClass('hide-accord');
$('div.content-accord.uc-accord-'+liter+'-'+ind+'').removeClass('hide-accord');
videoStop();
};

}else{
//По несколько вкладок
cT.toggleClass('active-accord');
$('div.content-accord.uc-accord-'+liter+'-'+ind+'').toggleClass('hide-accord');
videoStop();
};

     if(scroll){ //скролл до вкладки
            let el = $(this).closest('.r');
            setTimeout(function(){
                $('html, body').animate({scrollTop:  el.offset().top-50   }, 400);
            }, 600);
        };

});

});

});
</script>

<style>
.hide-accord {
height: 0!important;
pointer-events: none!important;
}
.content-accord.time-step , .accord-icon { transition: all 0.4s ease-in-out}
.content-accord {
padding-top: 0!important;
padding-bottom: 0!important;
overflow: hidden!important;
}
.active-accord .accord-icon { transform: rotate(180deg)}
.accord { cursor: pointer}
</style>
Библиотека для примера
Заголовок в Zero, а выпадающий стандартный блок

<script>
$( document ).ready(function() {
    
$(function () { 
    let liter = 'a'; //Литера для сборки
    let oneAcc = true; // Открывать по одной вкладке  false - true
    let accOpen = false; // Открытая  вкладка  false - true
    let openNum = 3; // Номер открытой вкладки
    let scroll = false; // Скролл к открытой вкладке  false - true

    $('.accord-icon').addClass('accord');
    
	$('div[class*="uc-accord-'+liter+'"]').each(function(index){
        $('.uc-accord-'+liter+'-'+index+':first').addClass('title-accord').attr('data-accord-index', index);
        $('.uc-accord-'+liter+'-'+index+'').not(':first').addClass('content-accord hide-accord');
        
	});
	
	if(accOpen){
	    $('div[class*="uc-accord-'+liter+'-'+openNum+'"]').addClass('active-accord');
	    $('div.content-accord[class*="uc-accord-'+liter+'-'+openNum+'"]').removeClass('hide-accord');  
	};
	
	setTimeout(function(){ $('.content-accord').addClass('time-step')}, 1500);

	function videoStop(){
	    setTimeout(function(){ 
	        $('div.content-accord.hide-accord[class*="uc-accord-'+liter+'-"]').each(function(){
	            let videoNum = $(this).find('div[data-elem-type="video"]').length;
	            if(videoNum){
                    $(this).find('div[data-elem-type="video"]').each(function(){
                        $(this).find('iframe').attr( 'src', function ( i, val ) { return val; });
                    });    
	            };
	        });
	    }, 300);
	};

	$('div[class*="uc-accord-'+liter+'"]').find('.accord').click(function(e){
        let cT = $(this).closest('.title-accord');
        let ind = cT.attr('data-accord-index');
        
        
        if(oneAcc){
            //По одной  вкладке
            if( cT.hasClass('active-accord') ){
                cT.removeClass('active-accord');
                $('div.content-accord.uc-accord-'+liter+'-'+ind+'').toggleClass('hide-accord');  
                videoStop();
            }else{
                $('div.title-accord[class*="uc-accord-'+liter+'"]').removeClass('active-accord');
                cT.addClass('active-accord');
                $('div.content-accord[class*="uc-accord-'+liter+'-"]').addClass('hide-accord');
                $('div.content-accord.uc-accord-'+liter+'-'+ind+'').removeClass('hide-accord');  
                videoStop();
            };
     
        }else{
            //По несколько вкладок
            cT.toggleClass('active-accord');
            $('div.content-accord.uc-accord-'+liter+'-'+ind+'').toggleClass('hide-accord');  
            videoStop();
        };
        
            if(scroll){ //скролл до вкладки
            let el = $(this).closest('.r');
            setTimeout(function(){
                $('html, body').animate({scrollTop:  el.offset().top-50   }, 400);
            }, 600);
        };

	});
    
});
      
});
</script>

<style>
.hide-accord  {
    height: 0!important;
    pointer-events: none!important;
    overflow: hidden!important;
}    
.content-accord.time-step, .accord-icon {   transition: all 0.4s ease-in-out}    
.content-accord {
    padding-top: 0!important;
    padding-bottom: 0!important;
}
.active-accord .accord-icon {  transform: rotate(180deg)}
.accord {  cursor: pointer}
</style>
Made on
Tilda