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 the navigation dropdown toggle triggered by both mouseout and when hovering off of it?

I'm looking for some assistance in modifying the code so that the dropdown menu not only hides on click, but also hides on mouseout and/or when another top-level menu button is hovered over. View jsfiddle example $(document).ready(function () { ...

horizontal Bootstrap Image Gallery

I'm having an issue with Bootstrap Thumbnails. Currently, my thumbnails are stacked vertically like this: img01. However, I want them to be in a horizontal layout. What should I do? This is my code: HTML: <div class="hrs" align="center"> ...

Tips for avoiding flickering in a background image when it is being changed

Utilizing JavaScript, I am setting a repeated background image from a canvas to a div in the following way: var img_canvas = document.createElement('canvas'); img_canvas.width = 16; img_canvas.height = 16; img_canvas.getContext('2d' ...

Display the user's chosen background image as the backdrop for my activity

As I've been exploring various corners of the internet, I've come across a potential technique for accessing the user's background from within my activity. I've brainstormed a couple of ideas (even though they might seem silly, just to ...

Unable to modify background color in base website

While working on my project with Next.js, I encountered an issue where creating a button to change the color only affected the base web components' color and not the background color. _app.tsx import '../styles/globals.css'; import type { Ap ...

CSS for Adjusting Parent Height Based on Child Content

I've been working on adjusting the height of the parent class to fit the child class perfectly without overflowing Here is a snippet from my CSS file: Parent &__video position: relative; width: 471px; background: red; border-radius: 12px ...

My website is experiencing issues with LCP specifically on mobile devices. Instead of receiving a score, I am only presented with a question mark

After developing a website for a client, I noticed that while the desktop score was good, the mobile measurements resulted in an error. This issue could potentially impact the site's performance on Google. I suspect the animations rendered with lottie ...

Fade In and Contemplate CSS, Not Effective

Hey there! I'm trying to achieve a similar effect like the one shown in http://designshack.net/tutorialexamples/HoverEffects/Ex5.html. The issue is that the reflection of the image isn't displaying as it should. I've tried inspecting the ele ...

Modify the CSS borders to reflect a selected radio input type

I'm attempting to change the color of a Radio Button to blue when it's selected, but I'm having trouble achieving this. Here is the CSS code I'm using: /* Radio Button Style */ .radio { padding-left: 25px; } .radio label { di ...

Align pandas data frame to the right within a Flask application

My current project involves creating an API in Flask. One of the requirements is to display a pandas dataframe right next to the upload button on the web page. While I have been able to find information online about justifying column headers or text, I hav ...

PHP library dompdf is having issues when rendering CSS styles

Trying to convert HTML with CSS styles into a PDF using dompdf. The CSS includes floats as well. Below is the snippet of my CSS and HTML code: $dompdf = new DOMPDF(); //create object //load html with css $dompdf->loadHtml('<html> <head ...

High levels of cache misses occurring on NextJS ISR pages

The NextJs website we have implemented utilizes ISR, with each page scheduled to revalidate every 10 minutes. Initially, it was assumed that this would result in a maximum of 6 revalidations per page per hour. However, on Vercel, there are reports showing ...

Alignment issues with the layout

I am facing an issue with two containers stacked on top of each other. The bottom container is wider than the top one, and both have auto margins set for the left and right sides. I want the top container to be aligned evenly on top of the bottom one. I c ...

Using the Position Sticky feature in Next.js

As a newcomer to sticky elements, I decided to implement a sticky sidebar in my project. Unfortunately, after copying and pasting some code snippets related to sticky sidebars, it seems that the functionality is not working as expected. <Layout title= ...

The custom error component in Next.js fails to display on the screen

I'm encountering an issue with my custom error component in Next.js. Even though I followed the documentation and created a 404.js component in my /pages directory, it seems like it's not being recognized as it continues to display the default e ...

Changing the position from fixed to static

It's strange, but for some reason when I attempt to apply position:fixed using jQuery: $('#footer').css('cssText', 'position:fixed !important;'); to my footer, the result on the page is different: <div id="footer" ...

What is the best way to position a rectangle on top of a div that has been rendered using

I recently started using a waveform display/play library known as wavesurfer. Within the code snippet below, I have integrated two wavesurfer objects that are displayed and positioned inside div elements of type "container". My goal is to position my own ...

What is the best method for displaying an image from Firebase storage on my NextJs webpage?

I'm running into an issue with fetching an image from Firebase storage to my NextJs website as a beginner. After trying multiple solutions without success, I keep encountering the error message: "Image is missing required "src" propert ...

Error occurred while searching for the production build in Dockerfile for Next.js application

While testing a production dockerfile, I encountered an error message that reads as follows: Error: Could not locate a production build in the '/app/.next' directory. Please make sure to build your app using 'next build' before starting ...

Utilization of Bootstrap's .container class in various scenarios

As I delve into Bootstrap, the usage of the .container class is provoking some confusion. Most tutorials suggest a structure like this: -.container --.row ---.col- ---.col- However, I came across a different approach in a W3schools example: W3Schools - ...