The item image fails to load when Swiper is looped and using the next/prev buttons

I'm encountering an issue with swiper while trying to create a specific layout. This layout requires the first image to be larger than the others. Initially, I attempted to achieve this with a single slider but it caused miscalculations in the animations and slider numbering.

As a solution, I opted for two separate sliders that are linked together: https://i.sstatic.net/EP8AY.png

The problem arises when the swiper thumbnail fails to load the next/previous loop item correctly; it only loads when manually dragged. Additionally, upon reaching the last item, it does not create the next/prev looped item.

To better illustrate this behavior, here's a GIF: https://i.sstatic.net/kLtpc.gif

For a live demonstration, please refer to this pen: https://codepen.io/giovancruz/pen/wvORgXL

// JavaScript code snippet
const slidesWrapper = document.querySelectorAll(".js-slides-wrapper");

if (slidesWrapper) {
   // Iterate over each wrapper to set up sliders
  slidesWrapper.forEach((wrapper) => {
    const mainSliderElement = wrapper.querySelector(".js-main-slider");
    const thumbnailSliderElement = wrapper.querySelector(
      ".js-thumbnail-slider"
    );

    let thumbnailSlider = null;

    // Set up main slider
    const mainslider = new Swiper(mainSliderElement, {
      loop: true,
      effect: "fade",
      speed: 0
    });

    // Set up thumbnail slider
    if (thumbnailSliderElement) {
      thumbnailSlider = new Swiper(thumbnailSliderElement, {
        loop: true,
        spaceBetween: 20,
        slidesPerView: 1,
        navigation: {
          prevEl: wrapper.querySelector(".js-prev"),
          nextEl: wrapper.querySelector(".js-next")
        }
      });
    }

    // Connect both sliders
    if (thumbnailSlider && mainslider) {
      thumbnailSlider.controller.control = mainslider;
      mainslider.controller.control = thumbnailSlider;
    }
  });
}
// CSS Styles
html,
body {
  width: 100%;
}

.slides-wrapper {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
/* Additional CSS styles omitted for brevity */
// External resources
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5a283f293f2e773929291a6f746a7468">[email protected]</a>/reset.min.css">
// Include any other necessary external scripts or stylesheets.

Answer №1

To resolve this issue, it is recommended to adjust the responsive slidesPerView according to your requirements.

The reason for this issue may be due to Swiper not recognizing that you are close to the end of the visible items because of the negative margin on the swiper wrapper.

If you still need that css, consider applying it to a new wrapper instead of using the same one with the .swiper class.

thumbnailSlider = new Swiper(thumbnailSliderElement, {
  loop: true,
  spaceBetween: 20,
  slidesPerView: 3,
  navigation: {
    prevEl: wrapper.querySelector(".js-prev"),
    nextEl: wrapper.querySelector(".js-next")
  }
});
 .thumbnail-slider {
    width: 100%;
  }

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

Error encountered when executing MySQL query using Node.js

I am trying to use Node JS and MySQL to check if a user already exists in the database. I have included the code snippet below: var username = "RandomUsername"; var email = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5b093 ...

Error encountered in Node.js/Express: Unable to render the 'title' parameter

Currently, I am diving into the world of Node.js by following along with Sam's "Node.js in 24 Hours" book. Chapter 8 has proven to be quite challenging for me, taking more than an hour to grasp! Example 07 in this chapter guides the programmer on crea ...

`How can a child component in Next.js send updated data to its parent component?`

Currently diving into Next.js and tinkering with a little project. My setup includes a Canvas component alongside a child component named Preview. Within the Preview component, I'm tweaking data from the parent (Canvas) to yield a fresh outcome. The b ...

Tips for creating a header.php and footer.php integrated with CSS files

I am in the process of constructing my website using HTML files. I want to make sure that my header and footer sections are dynamic so I can easily modify them without having to update numerous files each time. While I've attempted a few methods based ...

Enter a value into the input field with a single click

I am trying to accomplish the following: As I type on each line of a textarea, I want to automatically add a + symbol at the beginning of that line. The desired scenario is as follows: When the user starts typing on the first line, a + should appe ...

Asynchronous requests in Node.js within an Array.forEach loop not finishing execution prior to writing a JSON file

I have developed a web scraping Node.js application that extracts job description text from multiple URLs. Currently, I am working with an array of job objects called jobObj. The code iterates through each URL, sends a request for HTML content, uses the Ch ...

Tips for designing adjustable text in bootstrap 4

Could someone please assist me with making text responsive using Bootstrap 4? I have searched everywhere but it's strange to see that there are no tutorials on this topic. Below are my codes in case you would like to provide guidance. <div class=" ...

Tips on converting Django model into desired format for Bootstrap-tables plugin integration

I want to integrate the bootstrap-table plugin with server-side functionality using Django Rest Framework to populate the data on the table. However, I keep getting the message "No matching records found". After some investigation, I discovered that a spec ...

The input field does not adhere to the maximum length property

I am working on a React method that is supposed to create an input field with a set maximum length: displayInputField: function(name, placeholder, updateMethod, maxLength) { return ( <div className="form-group form-inline"> ...

Button functions properly after the second click

import { Input, Box, Text, Divider, Button } from '@chakra-ui/react'; import { useState } from 'react'; export default function GithubSearchApp() { const [username, setUsername] = useState(''); const [data, setData] = use ...

Determine the absence of values in a randomly generated array and identify the quantity of missing values

My current challenge involves solving CodeSignal projects, and I recently encountered a problem where a random array of numbers is given, requiring me to determine how many additional numbers are needed to make the array consecutive. For instance, if the ...

Transmitting an HTML file along with JSON data and enabling the browser to refresh the JSON data without reloading the entire

I'm currently working on a project involving a browser-server program where the browser sends an http get request to ''. The server is expected to return both an HTML page and a JSON response. I attempted using res.render(), passing the JSON ...

Guide on configuring and executing AngularJS Protractor tests using Jenkins

I am encountering an error with the following configuration: ERROR registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match the current platform LINUX 18:17:05.892 INFO ...

Extracting data from a MySQL result array

I've encountered an issue with extracting a value from an array containing JSON data. Below is the JSON data I received (printed using console.log(rows[0])): [ { User_ID: 28, Email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email ...

Struggling with incorporating a button into a ReactJS table

I am trying to display a (view) button in the table, but I encountered the following error: Module parse failed: Unexpected token < in JSON at position 165 while parsing near '...2021", "view": <button type="submit...' You m ...

Changes in the external JavaScript file are not being displayed when the event is triggered

I have included an external JavaScript file in my Master .aspx file like this: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <asp:ContentPlaceHolder ID="head" runat="server"> &l ...

Increase the width in a leftward direction

I am looking to increase the width from right to left. <div dir="rtl" id="progress"> <dt id='dt'></dt> <dd id='dd'></dd> </div> The ultimate objective here is to have this progress bar progr ...

Mirror your html and css horizontally

Currently, I am working on a project that requires the implementation of a unique feature: two trees positioned next to each other, creating a mirror effect. Please refer to the visual representation: While I have managed to successfully flip the trees ho ...

Issue with Access Denied Error in Internet Explorer 11 when Using AngularJS

Every software development process consists of two essential components. FIRST, the hard work of developing the application. SECOND, the even harder task of making it compatible with the notorious Internet Explorer. Currently, we have an AngularJS (v1.3.1 ...

Javascript's ReferenceError occasionally acts inconsistently when using Firefox's scratchpad

While delving into the world of Javascript for learning purposes, I encountered an unexpected behavior. Let's explore this scenario: function hello(name) { let greet = 'Hello ' alert(greet + name) } hello('world') alert(gree ...