The Glider.js function appears to be malfunctioning as my carousel, powered by Glider.js, is failing to operate

I have been attempting to set up a carousel using the glider.js library from . Despite following all the instructions, the carousel is not functioning properly. Could you please assist me? When I click on the arrow, it does not 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>

Answer №1

Issues found in your code:

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

  2. The dragable parameter is invalid, it should be draggable;

  3. There is an extra closing div </div> at the end of the markup, although not critical.

To ensure greater reliability, consider wrapping the initialization in

window.addEventListener('load', function() { ... })
, even though it may not be necessary in this case as everything is ready before initialization. The author recommends wrapping it according to the usage tab on .

Below is a minimal working glider configuration example:

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>

Answer №2

Make sure to load the script files before the closing body tag in your HTML document.

Additionally, call Glide after the window has finished loading completely.

window.addEventListener('load', function(){
  new Glider(document.querySelector('.glider'), {
        slidesToShow: 3,
        draggable: true,
        arrows: {
            prev: '.glider-prev',
            next: '.glider-next'
        }
    })
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Communicate with the parent component in React to either access data or pass data from parent to child component

Can you explain a method for passing data between components without using props? render() { return ( <Parent> <Child1> <Child2> </Parent> ); } In the context of components Parent and Child, how can the data genera ...

Unraveling Vue Async Components - Harnessing the power of emitted events to resolve

I am looking to create a Vue async component that stays in a loading state until a custom event is triggered. This means it will render a specified loading component until the event occurs. Here's an example of how I want it to work: const AsyncComp ...

Combining Text and Images with a Background Video using CSS

I need help replicating a unique design I came across in a graphic design mockup. It involves a background video with a transparent green overlay, an image of a man fixed to the right side, and text flowing over it. I've managed to recreate most of it ...

Explore the Image Gallery feature that dynamically adjusts the width and height of images for optimal viewing experience

I am currently creating a unique photo gallery that showcases images uploaded by users. These images are resized to fit the gallery but can vary in dimensions from 100x100 to 2500x2500. The Photo Gallery View page I have designed is Fluid, meaning the wid ...

`Why isn't Angular updating when watching window.pageYOffset?`

Within my controller, I have the following code: $scope.woffset = window.pageYOffset; $scope.$watch("woffset", function (newValue, oldValue) { console.log("hello"); console.log(window.pageYOffset); }, true); }); My expectation is to receive co ...

Struggling with creating a CSS navigation bar, having issues with hover functionality

I have a question about the navigation menu I created using CSS. I have included a sub-menu that appears when hovering over the main menu item, along with a triangle created with CSS placed underneath the menu. You can view the sample code here: http://js ...

Issue with click event not triggering initial interaction with dynamically inserted elements through AJAX requests

I am experiencing an issue with my ul element that is being populated with li elements through AJAX. When I try to click on these li elements, something peculiar happens. The functionality only works when I click for the second time, not the first. Despit ...

Is the AJAX $.ajax() function and setInterval() method activated only when a user is actively viewing the page?

The following code was created by me in order to refresh or reload the content within the div id='bitcoin_blocks_table', which only occurs when a user is actively on the website. I noticed that if no one is on the site and I return after 2 hours ...

Retrieve the names of columns from a variable by parsing JSON data

I have a variable that stores all the subject names which are also column names in a table. Now that I have captured all the column names in a variable, I want to use this variable in a select statement. Using Ajax success:function(result) { console ...

CSS Word Break and Word Wrap functionality appears to be malfunctioning

Can someone please assist me with an issue I am facing? The word wrap or word break functionality is not working on my string. Here are the details: The company has seen a steady increase in revenue over the past five years, with a total growth of 49% bet ...

Having trouble getting a background image to show up using node.js?

Hi there, I have a quick and simple question. I am attempting to include a div with a background-image in my *.ejs page file. <style> .signPage{ background-image: url("//back.jpg"); width: 98%; height: 98vh; top: ...

Experiencing issues with Ajax Data Call in Codeigniter, whether or not a slash is included

If my URL is example.com/controller/method/, using this ajax code changes the URL to example.com/controller/method/method which is not retrieving data. function getProductList() { var category = document.getElementById('Category').value ...

Issue with activation of onClick event in case/switch statement

Currently working on a JavaScript project to recreate the Fallout terminal game, with one of the main aspects being comparing words selected by the user to those chosen by the computer. The concept of this hacking game is reminiscent of the board game Mas ...

Animating CSS Skill Bars as You Scroll

Is there a way to achieve a similar effect as seen here? I've tried implementing the code from this answer, but it's not entirely clear. The suggestion is to use this jQuery plugin, but I can't seem to make it work. I prefer using Foundation ...

Is it possible to retrieve the ID of an anchor tag when the text within two table items meets my specified criteria?

https://i.sstatic.net/pQU32.png In the table with ID "PTSRCHRESULTS," each row contains anchor links. I am trying to find the ID of an element within a row that contains both "Undergrad" and "1". This is for Power Automate Desktop, but I can use JavaScrip ...

Disabling ngIf but still utilizing ngContent will render the template bindings

Creating a basic component in the following way: @Component({ selector: 'loader', template: `<div *ngIf='false'> <ng-content></ng-content> </div>`, }) export class Loader {} When it is imple ...

Leverage the power of Angular's route resolve function

Can anyone assist me with a problem I'm facing? I am looking for a way to delay the display of a view until my data is loaded. After some research, I was thinking of using a resolve in the route, but I can't seem to figure out how to implement it ...

Updating a JSON array by including a new key-value pair using Javascript

Below is a json string that needs to be converted into a new Json Array: Raw Data: [ ["yrxqBHmPkNhZ60_eab97ebf-c2a3-40a5-972a-91597ad9a4ca_99371", "SUCCEEDED", "2023-08-31T21:59:31.325000+05:30", "2023-08-31T22:13:42.165000+05:30"], ["yrxqBHmPkNhZ ...

Utilizing AngularJS in conjunction with Asp: UpdatePanel

<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMasterpage.master" AutoEventWireup="true" CodeBehind="ExamSet.aspx.cs" Inherits="demo.Admin.ExamSet" %> <asp:Content ID="Content1" ContentPlaceHolderID="content" runat="server"> <s ...

What steps can I take to allow a third-party JavaScript to access my TypeScript object?

I am working on an Angular application and I have a requirement to develop an API for a third-party JavaScript that will be injected dynamically. public class MyApi{ public callSomeFunction():void{...} public getSomeValue():any {...} } var publicA ...