Adding a class name to the three active, visible, and shown slides in SwiperJS is a simple process that can be done by

Currently, I am working on customizing a carousel in Swiper with slidesPerView={3}. My goal is to style the sliders that are not visible on the screen. I have made multiple attempts to achieve this:

First, I tried adding the attribute

slideActiveClass="swiper-slide-active"
, but it seems that it is not compatible with React or Next.js. However, upon inspecting the elements, I found that the active class was present even without explicitly setting it.

.swiper-slide:not(.swiper-slide-active) {
    /* CSS styles here */
}

The above styling method only targeted the first visible slider, not all three visible sliders as intended.

Next, I attempted to use

slideVisibleClass='swiper-slide-visible'
, but unfortunately, this approach also did not work with React and Next.js. Upon inspection, I noticed that the specified className was missing compared to the active class.

Lastly, I experimented with slidesPerGroup={3} thinking it would group the 3 sliders and apply the active class to all of them. However, this resulted in advancing by 3 slides instead of 1 for each navigation action.

Despite searching for more insights, I have yet to find a suitable solution to style the non-visible sliders effectively.

  • "swiper": "^8.4.2"
  • "next": "12.3.0",
  • "react": "18.2.0",

Answer №1

At this moment (slideVisibleClass is not supported in Swiper Angular/React/Svelte/Vue). One simple workaround is to implement basic logic (although it may not be as flexible).

Generally, for displaying 3 slides per view (without center mode), the visible slides would be:

[1_active][2_next][3_last][4][5][6]

1_active:

.swiper-slide.swiper-slide-active

2_next

.swiper-slide.swiper-slide-next
  1. 3_last: + selector selects the slide placed immediately after 2
.swiper-slide.swiper-slide-next + .swiper-slide

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

Is it possible to create a mouse-following effect with lighting using Javascript

Recently, I've been honing my Javascript skills and decided to create a follow-mouse function. After successfully implementing it, I started brainstorming a new concept that I'm unsure is achievable. Is there a way to develop an "orb of vision" ...

Implementing a feature that ensures html elements are transparent in a PDF conversion

I am in the process of converting a webpage into a format that is easily printable as a PDF, while ensuring that it maintains the same appearance. Many tools for printing to PDF do not support background images or colors, so I am attempting to overcome thi ...

Trouble keeping HTML/Javascript/CSS Collapsible Menu closed after refreshing the page

My issue is that the collapsible menu I have created does not remain closed when the page is refreshed. Upon reloading the page, the collapsible menu is always fully expanded, even if it was collapsed before the refresh. This creates a problem as there is ...

"Unfortunately, the Datatables Individual Column Search feature is not compatible with the

I am currently using Datatables to showcase a large dataset with over a thousand rows in a table format. To enable users to search for specific information within each column, I have implemented the feature of individual column search. The initial setup of ...

Is it necessary to alter the number of rows or columns in the table?

I'm having an issue with my code where the table is not changing the number of rows based on the selected input option. It seems to only read the first value of the select id and does not update the rows accordingly. Can someone help me identify the m ...

Creating a triangle shape using Bootstrap to style a div element, similar to the image provided

Trying to achieve the look of the attached image with a few divs. I know I can use a background image like this: background:url(image.png) no-repeat left top; But I'm curious if there's another way to achieve this without using a background ima ...

Tips for extracting links from a webpage using CSS selectors and Selenium

Is there a way to extract the HTML links per block on a page that renders in JavaScript? Would using CSS or Selenium be more effective than BeautifulSoup? If so, how would I go about utilizing either of those methods to achieve the extraction of the HTML ...

Is there a way to modify the code of a component in react so that it retrieves the data as an array?

I am currently facing an issue where I can only upload a single image using this component. Is there a way to modify my code so that I can upload multiple images by simply dragging and dropping them? Below is the code for my component: import React, { us ...

Exploring etoro data through python web scraping

Attempting to automate the process of logging into my etoro account and extracting data from my portfolio using Selenium. Currently working on Google Colab, here is what I have so far: from selenium import webdriver options = webdriver.ChromeOptions() opt ...

Incorporating pre-designed elements into the bottom section of my

I'm currently facing an issue while trying to integrate a footer content from a template into my slideout footer. The problem is that the template footer is currently spanning across the entire width of the page, and I am struggling to contain it with ...

Easiest method to restrict entry to a particular Next.js route

In my Next.js project, I have two pages and two API routes for which I want to restrict access. To achieve this in a simple way due to the low complexity of the project, I am currently using an unguessable string in the path to these pages. While the actua ...

How can you troubleshoot code in NextJS API routes similar to using console.log?

Incorporating nextjs API routes into my upcoming project has been a priority, and I recently encountered an issue with code execution upon sending a POST request. Debugging has proven to be challenging since I am unable to use conventional methods like co ...

How can you center a div at the top of another div?

I am working with a nested div structure and trying to center the inner content of one div within another. Is it possible to achieve this using CSS? <div id="outer"> bla, bla....... <div id="inner"> <p>Test</p> </div> ...

Guide on dynamically caching a Server Side Rendered Page in Next.js with Dynamic Routes

I am in the process of deploying a Next.js Application on AWS using ECS/Fargate because I have specific requirements that prevent me from using Amplify for custom logging and monitoring purposes. My application utilizes api-routes and dynamic-routes with S ...

Is it possible for us to customize the angular material chip design to be in a rectangular shape

I recently implemented angular material chips as tags, but I was wondering if it's possible to customize the default circular design to a rectangle using CSS? ...

CSS3 Arrow missing from display

Is there a way to create a box with an arrow on its right center using CSS? Here is the code I have so far, but the arrow is not displaying. Any suggestions? CSS: .pageHelp{ float:right; margin:10px 20px 0 0; width:85px; height:25px; border-radius:3px; b ...

Having issues with importing images in Next.js using the Next Images package

Having trouble with importing images locally from the images folder. Error message: "Module not found: Can't resolve '../images/banner1.jpg'" https://i.stack.imgur.com/Dv90J.png Attempting to access images in ImagesSlider.js file at compo ...

Can you identify the method used to apply CSS classes to an element?

Looking for clarification, I've noticed a pattern of "adding" (although unsure if that's the correct term) classes to elements in HTML UI frameworks. For instance, considering an element with these class attributes: class="mif-earth mif-2x" To ...

Some CSS styles are not displaying correctly within an iframe

Let me start by clarifying that I am not looking to add extra CSS to the contents of an iframe from the parent document. My issue lies with a document that normally displays correctly but experiences styling issues when shown in an iframe. Whenever I searc ...

Is it normal that my website isn't scrollable on an iPhone?

I have a hunch that the issue is related to the CSS, or perhaps it could be due to including the parallax JavaScript library. You can view the site at Below is the SASS code snippet: @import "compass/css3"; /* Sticky footer styles ---------------------- ...