dynamicweb / swiffy-slider

Super fast carousel and slider with touch for optimized websites running in modern browsers.
MIT License
250 stars 29 forks source link

Indicator is not working in mobile view. #95

Closed waleedarshad closed 4 months ago

waleedarshad commented 4 months ago

Describe the bug We have a list of images that are shown and hidden conditionally. On load, we display one set of slides along with the indicators, and the slides work perfectly fine. However, once we display the other set of images, the slider works but the indicators do not function with the slider.

Expected behavior The indicators should work correctly when we conditionally show the other set of images.

Additional context Tested in browser in mobile view.

This is the code we are calling on indicator click to move to that sliders

`

      handleIndicators () {
          const indicatorSlide = (index) => {
            const hasSliderElement = document.querySelector(".has-indicators");
            if (hasSliderElement) {
        setTimeout(() => swiffyslider.slideTo(hasSliderElement, index));}
        };
        const indicators = document.querySelector("ul.slider-indicators").getElementsByTagName("li");
        indicatorSlide(0);

      for (let i = 0; i < indicators.length; i++) {
        indicators[i].addEventListener("click", function (event) {
          event.preventDefault();
          event.stopImmediatePropagation();
          indicatorSlide(i);
        });
      }
}
`
nicped commented 4 months ago

Swiffy slider is markup first. If you have one set or number of slides in mobile view and another set or number of slides in desktop mode, you create to indicator sections and use responsive css to hide and show the correct one.