Splidejs / splide

Splide is a lightweight, flexible and accessible slider/carousel written in TypeScript. No dependencies, no Lighthouse errors.
https://splidejs.com
MIT License
4.89k stars 424 forks source link

RTL fade issue #1140

Open rachelies opened 1 year ago

rachelies commented 1 year ago

Checks

Version

4.1.4

Description

When setting direction to rtl and using type fade the slider does not work properly, to correct this issue I think this need to be changed

src/js/transitions/Fade/Fade.ts:36
from current
Slide.style( 'transform',translateX(-${ 100 Slide.index }%));
to
Slide.style( 'transform',translateX(${ options.direction === 'rtl' ? '' : '-' }${ 100
Slide.index }%));

I could not compile the source so I did not create A PR, can someone implement this? Thank you.

Reproduction Link

No response

Steps to Reproduce

.

Expected Behaviour

.

code-r-man commented 1 year ago

@rachelies I could not implement it in the source code (couldn't get the rtl value from the options), but I used JS to "patch" it like so:

    const splide = new Splide( '.splide', {
      type:'fade',
      perPage: 1,
    });

    const isRtl = function () {
      const html = document.querySelector('html');
      const dir = html.attributes.getNamedItem('dir');

      if (dir) {
        if (dir.value === 'rtl') return true;
      }

      return false;
    };

    if (isRtl()) {
      splide.on('ready', function (e) {
        const slides = splide.root.querySelectorAll('.splide__slide');

        slides.forEach(function (slide) {
          const transform = slide.style.transform;

          slide.style.transform = transform.replace('-', '');
        });
      });
    }

    splide.mount();