Skip to content

zIndex needs to be opposite of item index #1

@aamorozov

Description

@aamorozov

Hi Nicolas, first of all great work on this lib! I was wondering if the line below is intentional and if it should be the other way around - currently the zIndex of each slide depends on an array index in an item. It seems odd to me because this makes the initial slide to be actually the last slide/item in an array.

https://github.com/NicolasSaikali/react-scroll-slider/blob/main/src/scroll-slider/index.tsx#L134

Replacing it with the following util function does the trick for me:

function getZIndexBasedOnIndex(
  index: number,
  slides: ScrollSlideType[]
): number {
  if (index >= 0 && index < slides.length) {
    return (slides.length - index) * 10
  }
  return 0
}

and then

          zIndex: getZIndexBasedOnIndex(index, this.props.slides),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions