SwiperJS: Issue with slide order and slide per column functionality within grid layout

sandbox: demo

Swiper version: ^11.0.5

The arrangement of slides and rows per column is not as expected. I am currently using Vue with the swiper component, but the issue persists even in a simple HTML demo. To achieve 3 rows per column in a single view, I have configured it like this:

  1. slidesPerView: 1
  2. grid: { rows: 3, fill: "row" }

However, only 2 rows are displayed on the first page and the order is incorrect.

Since I am iterating through the slides dynamically, fitting 3 elements into a single slide is not feasible.

I attempted to remove the fill property, but then all slides appeared on the first page. Modifying the CSS of .swiper-wrapper by using display: grid; grid-template-rows: repeat(3, 1fr); also did not yield the desired outcome. SlidesPerColumn does not seem to function in this version of Swiper.

Is there a possible solution to address this issue?

Expected behavior

for 1st page

1

2

3

for 2nd page

4

Actual behavior

for 1st page

1

3

for 2nd page

2

4

Answer №1

Adjust the grid option from fill: "row" to fill: "column"

Check out the updated codesandbox

Take note of the CSS code in your sandbox, even though it's currently commented out. It may cause all four slides to display on a single page:

swiper-slide {
  height: calc((100% - 30px) / 4) !important;
}

This could be the reason for the issue you previously encountered. Ensure that the value in the calculation matches the number of rows. Swiperjs will handle the correct calculation automatically if this CSS is disabled, but if you decide to enable it, make sure to update the height calculation to (100% - 30px) / 3.

Answer №2

When working on an actual project, I tackled the problem using this method.

  1. Adjust the height of the swiper container (for example, set it to 70vh) and
  2. Change the layout to column

If you experience issues swiping through slides and only get halfway through, try adding .swiper-wrapper { width: 0 !important; } to fix the problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

tslint issues detected within a line of code in a function

I am a novice when it comes to tslint and typescript. Attempting to resolve the error: Unnecessary local variable - stackThird. Can someone guide me on how to rectify this issue? Despite research, I have not been successful in finding a solution. The err ...

Reflections on the Javascript Prototype Design Pattern

After using a Javascript revealing module pattern, I'm now transitioning to a new approach which seems to be working. However, I'm not entirely sure if I'm following the best practices. Specifically, I want to know if my method of preserving ...

React, facing the challenge of preserving stored data in localStorage while accounting for the impact of useEffect upon

Seeking some assistance with the useEffect() hook in my Taking Notes App. I've set up two separate useEffects to ensure data persistence: one for when the page first loads or refreshes, and another for when a new note is added. I've added some l ...

Setting up camera in ThreeJS

I am brand new to ThreeJS and currently trying to incorporate it into my web application. I have encountered a problem with configuring the camera. Currently, I have a perspective camera that is able to look at and move in every direction within my scene. ...

Troubleshooting MaterialUI Datatable in Reactjs: How to Fix the Refresh Issue

Currently, I am facing an issue with rendering a DataTable component. The problem is that when I click on the "Users" button, it should display a table of Users, and when I click on the "Devices" button, it should show a table of Devices. But inexplicably, ...

AngularJS and Karma: Revoking ng-dirty status using setPristine

I'm currently facing an issue in one of my unit tests where I am testing the removal of ng-dirty when using setPristine on an input element. Even after calling setPristine, the ng-dirty is not being removed. My suspicion is that I may be incorrectly ...

Inquiring about socket.io: How can an io emit its own signal?

I am currently working on implementing the emit event in an express router, and I'm attempting to pass a global.io variable. However, I've encountered an issue where despite adding the following code: io.emit('join','Tudis' ...

Encountering a problem while trying to scrape using cheeriojs

While attempting to scrape article links from a website, I encountered an issue where only one link was successfully scraped and the other elements were not being looped over. My current setup involves using nodejs in conjunction with the cheerio and req ...

Creating markers from Mysql database is a simple and efficient process

On my website, I have an array of markers that I use to display locations on a Google map. The array format I currently use is: generateMarkers([['Location', lat, long], ['Location2', lat2, long2],['Location3', lat3, long]3]) ...

ways of exporting and using arrays in Node.js

Constantly receiving the "undefined" error in main.js: var dbAccess = require('../dao/dbAccess'); dbaInstance = new dbAccess(); var wordPool = dbaInstance.getWordPool(); console.log (wordPool); The contents of "dbAccess.js" are as follows: var ...

Tips on concealing all classes except one through touch swiping

If you have a website with a single large article divided into multiple sections categorized as Title, Book1, Book2, & Book3, and you want to implement a swipe functionality where only one section is displayed at a time, you may encounter some issues. ...

Create a roster of individuals who responded to a particular message

Can a roster be created of individuals who responded to a specific message in Discord? Message ID : '315274607072378891' Channel : '846414975156092979' Reaction : ✅ The following code will run: bot.on("ready", async () = ...

What steps should I take to have a button initiate an AJAX request?

One of the tasks on my list involves a textbox and a button for interaction. Once text is entered into the textbox, I intend to trigger an AJAX request by clicking the button. The purpose of this AJAX call is to extract the text input and incorporate it i ...

Incorporating HTML elements into a Jade template

Can HTML elements be passed into a jade file? For example, I want to insert text into the p element and nest some content inside the code element within the p element. JSON with string data var news = { one : { title : "Using JSON", body : "Us ...

Internet Explorer encounters errors when processing LESS code

Currently experimenting with the combination of LESS and respond.js to facilitate the development of a new website. Both LESS and respond are incredibly useful tools. However, encountered several issues with LESS in Internet Explorer. Initially, while in ...

Adding a recently retrieved data to a current array in JavaScript and Vue.js

API route is fetching data, and I have implemented pagination to fetch post data. On page 2 of pagination, I want to append the fetched data to the existing array. Function utilized for data fetching const posts = ref([]); const page = ref(1); const get ...

Tips for displaying HTML5 validation messages when the input is changed

I am working on a form where I prefer not to submit it directly, as I am making an AJAX call instead. However, I still want the HTML5 validation messages to show up when an input field is left empty. I have managed to display the validation message when a ...

What is the recommended return type in Typescript for a component that returns a Material-UI TableContainer?

My component is generating a Material-UI Table wrapped inside a TableContainer const DataReleaseChart = (): React.FC<?> => { return ( <TableContainer sx={{ display: 'grid', rowGap: 7, }} > ...

Mastering the art of implementing dynamic template variables in TinyMCE

After exploring the 'full' example and conducting research on the Wiki and moxie forums, I have yet to find a solution. I am attempting to implement what the wiki states is possible, but encountered an issue when replacing the 'staffid' ...

Angular unable to register service worker

Looking to implement push notifications in my Angular app using vanilla JavaScript instead of the Angular service worker or @angular/pwa. In angular.json, I've specified the path to the js file under the script option. However, when the service worke ...