Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glider.js not working. My carousel, using glider JS is not working/

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>
like image 733
Jesús Bohorquez Avatar asked Mar 03 '23 19:03

Jesús Bohorquez


2 Answers

Problems in your code:

  1. the class for the arrow is incorrect, .glider.prev instead of .glider-prev;

  2. the dragable parameter is invalid, you need draggable;

  3. 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>
like image 129
bhoodream Avatar answered Mar 05 '23 09:03

bhoodream


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'
        }
    })
});
like image 40
Rkv88 - Kanyan Avatar answered Mar 05 '23 09:03

Rkv88 - Kanyan