I tried to create a carousel using glider.js from https://nickpiscitelli.github.io/Glider.js/. I followed all the steps, yet it is not working. Can you help me, please? I click the arrow and it doesn't move.
<div class="glider-contain">
<button class="glider-prev">
<i class="fa fa-chevron-left"></i>
</button>
<div class="glider">
<div> <img src="./img/barcelona-img.png" alt="Barcelona"></div>
<div> <img src="./img/madrid.png" alt="Madrid"></div>
<div> <img src="./img/paris.png" alt="Paris"></div>
<div> <img src="./img/paris.png" alt="Paris"></div>
<div> <img src="./img/paris.png" alt="Paris"></div>
</div>
<button class="glider-next">
<i class="fa fa-chevron-right"></i>
</button>
</div>
</div>
<script src="./glider.min.js"></script>
<script src="../index.js "></script>
<script>
new Glider(document.querySelector('.glider'), {
slidesToShow: 3,
dragable: true,
arrows: {
prev: '.glider.prev',
next: '.glider-next'
}
})
</script>
Problems in your code:
the class for the arrow is incorrect, .glider.prev
instead of
.glider-prev
;
the dragable
parameter is invalid, you need draggable
;
extra closing div </div>
at the end of markup, not critical.
For greater reliability, you can wrap the initialization in window.addEventListener('load', function() { ... })
, although this is not necessary in your case, since everything is ready before initialization. Although the author prefers to wrap https://nickpiscitelli.github.io/Glider.js/ (Usage tab).
Here is an example of a minimal working glider configuration:
new Glider(document.querySelector('.glider'), {
slidesToShow: 2,
draggable: true,
arrows: {
prev: '.glider-prev',
next: '.glider-next'
},
dots: '.dots'
})
.wrapperForDemo {
width: 500px;
max-width: 80%;
margin: 0 auto;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/glider-js@1/glider.min.css">
<script src="https://cdn.jsdelivr.net/npm/glider-js@1/glider.min.js"></script>
<div class="wrapperForDemo">
<div class="glider-contain">
<div class="glider">
<div><img src="https://placeimg.com/300/200/arch" alt="Barcelona"></div>
<div><img src="https://placeimg.com/300/200/animals" alt="Barcelona"></div>
<div><img src="https://placeimg.com/300/200/tech" alt="Barcelona"></div>
<div><img src="https://placeimg.com/300/200/people" alt="Barcelona"></div>
</div>
<button role="button" aria-label="Previous" class="glider-prev">«</button>
<button role="button" aria-label="Next" class="glider-next">»</button>
<div role="tablist" class="dots"></div>
</div>
</div>
H , i try loading the script files before the html body
also call Glide after window is completely loaded
window.addEventListener('load', function(){
new Glider(document.querySelector('.glider'), {
slidesToShow: 3,
draggable: true,
arrows: {
prev: '.glider-prev',
next: '.glider-next'
}
})
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With