Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to hide arrows if there are not enough slides to trigger scrolling? #229

Open
untitledgraphic opened this issue Mar 31, 2022 · 2 comments

Comments

@untitledgraphic
Copy link

In a scenario where I have six slides, but slidesToScroll is set to eight, both prev and next arrows are visible but disabled.

When there are more than slidesToScroll value (in this case eight) a disabled arrow makes sense as this indicates you have come to the end of the slides, but when both end up being disabled they are just unnecessary.

So, is it possible to hide the arrows if there are fewer slides than the value that slidesToScroll is set?

@Shekar742368
Copy link

+1

@14nd90
Copy link

14nd90 commented Jan 11, 2024

+1 for the feature

My workaround below - I had a multiple glider setup

const gliders = document.querySelectorAll('.glider');

function evaluateGliders() {

  gliders.forEach(glider => {

    const wrapper = glider.parentNode;

    const fnc = wrapper.querySelector(".glider-prev.disabled") &&
                wrapper.querySelector(".glider-next.disabled") ?
                  'remove' : 'add';

    wrapper.classList[fnc]('has-scroll'); 

    //use the below if container size is changed, for example
    Glider(glider).refresh();

  });

}

gliders.forEach(glider => {

  const wrapper = glider.parentNode;

  new Glider(glider, {
    slidesToShow: 'auto',
    itemWidth: 200,
    draggable: true,
    arrows: {
      prev: wrapper.querySelector('.glider-prev'),
      next: wrapper.querySelector('.glider-next'),
    }
  });

});

evaluateGliders();
window.addEventListener("resize", evaluateGliders);

Then use CSS to show/hide the buttons based on the presence of .has-scroll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants