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.

Wrong order calculation for multi-lines container

See original GitHub issue

In case if not all lines are full filled up the Swiper generate wrong source number. For example you can try 16 items, slidesPerColumn: 3, slidesPerColumnFill: ‘column’ in case if 6 columns are visible. Proposed fix is (core.js, starting in line 515:)

        // Calc slides
        var slideSize;
        var slidesPerColumn = s.params.slidesPerColumn;
        var slidesPerRow = slidesNumberEvenToRows / slidesPerColumn;
        var numFullColumns = slidesPerRow - (s.params.slidesPerColumn * slidesPerRow - s.slides.length);
        for (i = 0; i < s.slides.length; i++) {
            slideSize = 0;
            var slide = s.slides.eq(i);
            if (s.params.slidesPerColumn > 1) {
                // Set slides order
                var newSlideOrderIndex;
                var column, row;
                if (s.params.slidesPerColumnFill === 'column') {
                    column = Math.floor(i / slidesPerColumn);
                    row = i - column * slidesPerColumn;
                    if (column > numFullColumns || (column==numFullColumns && row==slidesPerColumn-1)) {
                        if (++row>=slidesPerColumn) {
                            row=0;
                            column++;
                       }
                    }
                    newSlideOrderIndex = column + row * slidesPerRow;
                    slide
                        .css({
                            '-webkit-box-ordinal-group': newSlideOrderIndex,
                            '-moz-box-ordinal-group': newSlideOrderIndex,
                            '-ms-flex-order': newSlideOrderIndex,
                            '-webkit-order': newSlideOrderIndex,
                            'order': newSlideOrderIndex
                        });
                }
                else {
                    row = Math.floor(i / slidesPerRow);
                    column = i - row * slidesPerRow;

                }
                slide
                    .css({
                        'margin-top': (row !== 0 && s.params.spaceBetween) && (s.params.spaceBetween + 'px')
                    })
                    .attr('data-swiper-column', column)
                    .attr('data-swiper-row', row);

            }

Thank you, -=A=-

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
petrusolofssoncommented, Mar 22, 2017

I have found a solution to this problem for my project. The problem seems to occur because of how CSS flexbox works with Swiper. It still fills the slides by row, and column is only simulated by using CSS order, so the last remaining items always show on the last row, instead of in the last column.

My solution is to calculate how many slides are missing to fill the whole grid, then append placeholder empty slides equal to number of missing slides to Swiper on init, and then Swiper will calculate and fill the columns correctly.

Code I’m using is here:

slidesPerView: 2,
slidesPerColumn: 4,
slidesPerGroup: 2,
onInit: function (swiper) {
    // Slides per column
    console.log('slidesPerColumn: ' + swiper.params.slidesPerColumn);
    // Total number of slides
    console.log('totalNumberOfSlides: ' + swiper.slides.length);
    // Slides outside even grid
    var slidesOutsideEvenGrid = swiper.slides.length % swiper.params.slidesPerColumn;
    console.log('slidesOutsideEvenGrid: ' + slidesOutsideEvenGrid);
    // Check if grid is totally filled
    if (slidesOutsideEvenGrid != 0) {
        console.log('not even grid');
        // Grid not totally filled, calculate slides needed to fill grid
        var slidesNeededToFillGrid = swiper.params.slidesPerColumn - slidesOutsideEvenGrid;
        console.log('slidesNeededToFillGrid: ' + slidesNeededToFillGrid);
        // Append as many empty placeholder slides needed to fill grid
        for (var i = 0; i < slidesNeededToFillGrid; i++) {
            swiper.appendSlide('<div class="swiper-slide"></div>');
        }
    }
}

Hope something like this can be implemented in core to solve the problem with filling columns correctly.

Live example can be found here: https://www.myresjohus.se/inspiration/hall/

0reactions
lock[bot]commented, Jun 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

`scalebox` scales the equation number in a multiline equation ...
First of all: I agree with Bernard's comment that scaling an equation is usually a bad idea. In my experience of long, horrible...
Read more >
Split Multiple Lines in a Cell into Separate Cells - YouTube
Download the feature file here: https://www.bluepecantraining.com/exc... In this video I demonstrate how to split multiple lines within a ...
Read more >
Measure height of multi-line TextView before rendering
Your solution is OK but it fails to work on my side, as I need the height to be calculated immediately once the...
Read more >
Multi-Line Truncation with Pure CSS
Truncating multiple lines is a bit harder. ... The trick there is to make a little box that is the same background as...
Read more >
How to enter multiple lines in one cell in Excel 2021 - Ablebits
You can write an Excel formula on multiple lines. Reply. Savan says: December 25, 2022 at 10:55 pm. When ...
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