Reputation: 99
This is the line of code I'm using. But it's not working. According to the documentation is should.
var content = "<div>Some Content</div>";
var index = some_value;
This line works:
$('#slides').slick('slickAdd', content);
This line doesn't work:
$('#slides').slick('slickAdd', content, index);
This is the resulting markup when using index:
<div id="#slides" class="slick-initialized slick-slider" style="height: 197px;">
<div class="slick-list draggable">
<div class="slick-track" style="opacity: 1; width: 0px; transform: translate3d(0px, 0px, 0px);">
[NORMALLY SLIDES SHOULD BE ADDED HERE]
</div>
</div>
</div>
Upvotes: 2
Views: 5051
Reputation: 622
It is adding at a given index. Look at the below code to have an idea.
$(document).ready(function(){
var slideIndex = 1;
var atIndex = 0;
$('.add-remove').slick({
slidesToShow: 3,
slidesToScroll: 3
});
$('.js-add-slide').on('click', function() {
slideIndex++;
$('.add-remove').slick('slickAdd', '<h3>Hey ' + slideIndex + '</h3>', atIndex);
});
})
.my-carousel{
max-width: 80%;
margin: 0 auto;
}
h3{
background: #f8f8f8;
color: #3498db;
font-size: 36px;
line-height: 100px;
margin: 10px;
width: 150px;
height: 150px;
position: relative;
text-align: center;
}
.js-add-slide{
background: #3498db;
color: #fff;
cursor: pointer;
display: block;
font-size: 16px;
margin: 20px auto;
padding: 20px;
text-align: center;
text-decoration: none;
width: 48%;
}
<html>
<head>
<title>My Now Amazing Webpage</title>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/[email protected]/slick/slick.css"/>
</head>
<body>
<div class='my-carousel'>
<div class="add-remove">
<h3>1</h3>
</div>
</div>
<div class='js-add-slide'>add slide</div>
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/[email protected]/slick/slick.min.js"></script>
</body>
</html>
Upvotes: 1