Issue with Swiper js autoheight property not adjusting to the height of the first slide

I'm currently using SwiperJs with autoheight functionality. My expectation was that when the slide changes, the container would adjust its height based on the content (simple images in my case). It does update the height on slide change.

The issue arises upon initial load where the slide seems to miscalculate the height and makes it a square, disregarding the actual content height.

Here are my dependencies:

"dependencies": {
      "next": "12.1.6",
      "react": "18.2.0",
      "react-dom": "18.2.0",
      "swiper": "^8.2.4"
    },

This is the component:

return (
    <article className='card mb-8 block'>
        <div className='w-full'>
            <Swiper autoHeight loop spaceBetween={0} slidesPerView={1}>
                {images.map((image, i) => {
                    return (
                        <SwiperSlide key={i}>
                            <div className='custom-img-container'>
                                <Image className='custom-img' layout='fill' src={image} objectFit='cover' />
                            </div>
                        </SwiperSlide>
                    )
                })}
            </Swiper>
        </div>
   </article>
)

Answer №1

After including the following two properties, everything appears to be functioning correctly:

  enableObservation: true,
  watchParentElements: true,

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

Exploring the concept of returning objects in jQuery

I'm really trying to grasp the inner workings of how jQuery creates the return object when searching for DOM elements. I've delved into the source code, but I must admit that it's not entirely clear to me yet. So, I'm reaching out here ...

Animating the fill of an SVG path

I am trying to fill a path that resembles a circle with color using animation. The color fill animation should follow a circular pattern, rather than filling from top to bottom or bottom to top. Here is my SVG code: <svg id="svg_circle" width="100%" ...

Ways to efficiently modify an array while retaining its immutability

Help needed! Any assistance would be greatly appreciated! I am working on updating the comments array in an immutable way within this object (just mock data for now): const initialState = { news: [ { id: 1, text: 'Hello!', ...

Sharing images on a web app using Express and MongoDB

My objective is to develop a portfolio-style web application that allows administrators to upload images for other users to view. I am considering using Express and MongoDB for this project. I am uncertain about the best approach to accomplish this. Some ...

Choosing the final row and then potentially looping in reverse

After receiving some great assistance here, I have another question. On a screen, there are multiple rows of clickable links with the same name. I need to click on the last row and determine if it's the correct one. If not, I have to backtrack and sel ...

How can Vue JS 3 components exchange data between each other?

I am attempting to share data from a variable favorite_count in the Favorites component located in the file Favorites.vue. My goal is to pass this data to the App Component in the App.vue file but I have been unsuccessful so far. I want any changes made to ...

What is the correct way to utilize preloads and window.api calls in Electron?

I am struggling with implementing a render.js file to handle "api" calls from the JavaScript of the rendered HTML page. The new BrowserWindow function in main.js includes: webPreferences: { nodeIntegration: false, // default value after Electr ...

Tips for lining up segmented pictures in HTML?

Recently, I was presented with a set of sliced images to insert into an HTML document. These images were not sliced by me, but rather provided as individual pieces. To showcase these images in a grid-like manner, I opted to construct a table layout. Each r ...

Is a local snapshot stored by Firebase Firestore?

In my chat room application, I am utilizing Firebase Firestore for data storage. One of the functions in my app handles sending messages to Firebase like this: const sendMessageHandler = message => { if (message) { firestore() .collection(` ...

Remove the triangle shape from the div and reveal the background

Is it possible to use CSS tricks to cut a triangle out of a div and show the background behind it? I didn't think this was achievable, but I know you pros can surprise me. Here's what I'm aiming for: Please don't suggest a 3-column sol ...

Tips for incorporating a return statement within a network request function that is already returning information pertaining to the request

Is there a way to retrieve the data extracted from within newReq.on('response', (response) => {? var request = require('request'); const cheerio = require('cheerio'); const { app, net, BrowserWindow } = require('elect ...

Creating text that adapts to various screen sizes when displayed over a video background

I am experimenting with having text displayed over a video background that adjusts to different screen sizes. I want the text to fill up the entire screen regardless of the browser size. What would be the most effective way to achieve this? Currently, I h ...

What causes the variance in behavior between the Angular-formly directive and type?

I am facing an issue with two input fields that are both generated using the same template. I have set the required attribute to true for both of them by using the following code snippet: ... templateOptions: { ... required: true } One input fiel ...

When the page is reloaded, JavaScript code remains unprocessed

Within a mobile website, there is a JavaScript snippet that appears as follows: <script type="text/javascript"> (function() { // actual function code is not shown here }()); </script> Upon initial page load, the code is successfully execute ...

Position the sticky navbar following the absolutely positioned div

I'm facing a challenge with a div that is supposed to occupy the entire initial screen and be floated both left and right. In order to achieve this, I had to set the div to equal 100% so that the floated elements could fully utilize the screen space. ...

Chrome's behavior of reducing the width of inline elements when the content is dynamic

Upon opening the specified URL in Google Chrome, an issue can be observed where on the initial load everything appears fine. However, upon refreshing, the width of the three items at the top (Bedingungen, Preise, and So geht's) collapse. This seems to ...

Guide on resetting a value in ajax search to enable pagination of results

I've run into an issue with a "load more button". Each time I perform a new search, I want to display the second page of results and subsequent pages. However, the value I'm using to determine the current page keeps increasing continuously. I nee ...

Add CSS styles to the outermost container element when the slideshow is currently in use

On my homepage, I have a carousel featuring multiple slides. However, when the third slide appears in the carousel, the positioning of the carousel buttons within the div class="rotator-controls" shifts downward due to the space taken up by the image. My o ...

Unexpected invocation of cleanup function in React useEffect

Currently, I am in the process of developing a custom hook that will handle API fetching upon form submission. To achieve this, I have incorporated an useEffect hook to make the API call and implemented a reducer to manage the states within the hook. Withi ...

Utilizing jQuery, the code can modify a basic element on a webpage by extracting JSON data from two external device buttons

This project I'm working on for school is quite simple. I am trying to change the background color of a webpage and more with the use of an external device that has two buttons (microbit a and b) connected to a serial port. The device writes data stri ...