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.

slidesPerColumn param update does not correctly render slides

See original GitHub issue

CodeSandbox: https://codesandbox.io/s/reactidswiper-slidespercolumn-update-issue-bww36?fontsize=14

What you did I am updating the slidesPerColumn param on window resize and re-rendering Swiper component with shouldSwiperUpdate set to true eg:

  useEffect(
    () => {
      if (swiper !== null) {
        swiper.on("resize", () => {
          if (window.innerWidth < 1024) {
            swiper.params.slidesPerColumn = 1
            swiper.params.slidesPerView = 1
          } else {
            swiper.params.slidesPerColumn = 3
            swiper.params.slidesPerView = 2
          }
          swiper.update();
        });
      }
    },
    [swiper]
  );

Expected Behavior Swiper should display 3 slides per column inside the Swiper container when window size > 1024

Actual Behavior Swiper displays only 1 slide per column at 100% of container height. slidesPerView renders correctly

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewjslackcommented, May 31, 2019

I have got it working on page load by setting init: false and then setting params before calling swiper.init()

eg:

  const setSlidePerColumn = swiper => () => {
    if (window.innerWidth < 1024) {
      swiper.params.slidesPerColumn = 1
      swiper.params.slidesPerView = 1
    } else {
      swiper.params.slidesPerColumn = 3
      swiper.params.slidesPerView = 2
    }
    swiper.init()
  }

  useEffect(() => {
    if (swiper !== null) {
      swiper.on('init', setSlidePerColumn(swiper))
      ....
    }
  }, [swiper])

However, it still does not update responsively on resizing and I am not sure how to handle this. I don’t think to destroy and recreate the swiper on each resize is feasible. Even if setting a timeout and waiting for a ‘done resizing’ event.

0reactions
ehssamimicommented, Jul 29, 2021

the answer is here

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can you modify the number of slidesPerView in swiperjs after ...
Solved it by modify the params. let params = swiperModify.params; params.slidesPerView = 3; params.slidesPerColumn = 3;.
Read more >
Swiper Changelog
a11y: update slides a11y on slides amount change (31e2005), closes #5692 ... Fixed issue when SwiperSlide was not rendered if used with v-for ......
Read more >
How to Build a Slideshow App Using Swiper and Angular
In this post, we will build a slideshow app with the ability to render one slide at a time using Angular, Swiper, and...
Read more >
Framework7 Release Notes
Fixed issue when it rendered not correctly without icon ... autoScrollOffset parameter that allows to set on what thumbs active slide from edge...
Read more >
Team:CMUQ/swiperjs - iGEM 2019
textContent = text; } return this; } function is(selector) { var el = this[0]; var compareWith; ... Calc slides var slideSize; var slidesPerColumn...
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