question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jumping indexes too far with `next`

See original GitHub issue

Hi there,

I’m experiencing an issue with a slider of 6 items where 4 are visible with perView. It seems that after moving right using next twice, to the last item, the track.details.abs goes to 2 (as it should), but then jumps to 4 for some reason. This causes attempting to move back using prev to go to the index 3, which doesn’t work.

I’m using it in Vue/Nuxt, as so:

<template>
  <section>
    <div ref="carouselWrapper">
      <Card
        v-for="item of items"
        :key="item.name"
        class="keen-slider__slide"
        v-bind="item"
      />
    </div>

    <button @click="slider.prev()">prev</button>

    <button @click="slider.next()">next</button>
  </section>
</template>

<script>
import {
  ref,
  onMounted,
  onBeforeUnmount,
} from '@nuxtjs/composition-api'
import KeenSlider from 'keen-slider'

export default {
  name: 'MyCarousel',
  props: {
    items: {
      type: Array,
      required: true,
    },
  },
  setup(props) {
    const carouselWrapper = ref(null)
    const slider = ref()

    onMounted(() => {
      slider.value = new KeenSlider(carouselWrapper.value, {
        slides: {
          perView: 4,
          spacing: 16,
        },
        created: () => {
          setTimeout(() => {
            // update immediately after mount
            slider.value && slider.value.update()
          }, 0)
        },
      })
    })

    onBeforeUnmount(() => {
      if (slider.value) slider.value.destroy()
    })

    return {
      carouselWrapper,
      slider,
    }
  },
}
</script>

Am I doing something foolish? Or could this be a bug?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ponciuszcommented, Mar 3, 2022

issue can be easily reproduced by setting high value for spacing.

image image
0reactions
rcbyrcommented, Mar 9, 2022

Seems to be fixed by the PR from ponciusz.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a way to jump ahead to a later index in the loop?
I'm working on an experiment in which I need to dynamically be able to repeat certain trials. I've read that jumping back is...
Read more >
List indexes - If too big go back to the beginning of the list
But my problem is that how could I tell python that if the index number goes up too high, it should start counting...
Read more >
Understanding ClickHouse Data Skipping Indexes
In circumstances where querying a table is too expensive unless a skip index is used, using this setting with one or more index...
Read more >
How to adjust bike gears | How to index gears and fix shifting ...
In this easy-to-follow guide, we talk through how to index gears, setting derailleur limits and replacing a hanger.
Read more >
Minimum number of jumps to reach end | Set 2 (O(n) solution)
Next subarray end index. // and so far calculated sub. // array max step cover value. subArrEndIndex = arr[firstHalfMaxStepIndex];.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found