If you click the Collapsible Group Items #1 the slick inside of it is broken when setting the variableWidth: false
. But if you set it to variableWidth: true
it is working fine.
Here is the bootstrap doc https://bootstrapdocs.com/v3.3.5/docs/javascript/
See the codes below:
$(function() {
$('.step-slider-a').slick({
slidesToShow: 4,
slidesToScroll: 1,
arrows: true,
infinite:false,
dots: false,
variableWidth: false,
responsive: [
{
breakpoint: 992,
settings: {
slidesToShow:3,
}
},
{
breakpoint: 768,
settings: {
draggable:true,
slidesToScroll:1,
slidesToShow:1,
centerMode:false,
arrows: true,
dots: false,
}
}
]
});
// $('a[data-toggle="collapse"]').on('shown.bs.collapse', function () {
// $('.step-slider-a').slick('setPosition');
// })
});
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick-theme.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
Collapsible Group Item #1
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<div class="row step-slider-a">
<div class="col-lg-3" style="width: 200px;">
<div>Content 1</div>
</div>
<div class="col-lg-3" style="width: 200px;">
<div>Content 2</div>
</div>
<div class="col-lg-3" style="width: 200px;">
<div>Content 3</div>
</div>
<div class="col-lg-3" style="width: 200px;">
<div>Content 4</div>
</div>
<div class="col-lg-3" style="width: 200px;">
<div>Content 5</div>
</div>
<div class="col-lg-3" style="width: 200px;">
<div>Content 6</div>
</div>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Collapsible Group Item #2
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingThree">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Collapsible Group Item #3
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
<div class="panel-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js" type="application/javascript"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
2
Answers
I have an alternative solution for this slick carousel inside accordion. First this is not the perfect solution because there is a glitch to its slick height especially on first load or every time you refresh the page.
I will keep this question open just in case others have better solutions than mine.
Updates:
css
to targetcollapsing
andcollapse.in
classes.shown.bs.collapse
for my accordion.Below is the updated code:
To address this, you’ll need to listen to Bootstrap’s collapse events (shown.bs.collapse and hidden.bs.collapse) and force Slick Slider to update its layout when these events occur.
Here’s how you can achieve this: