javascript - Swiper js autoheight prop not resizing for first slide height - Stack Overflow

So, I'm using SwiperJs with autoheight.I expected that on slide change the container adapts its h

So, I'm using SwiperJs with autoheight. I expected that on slide change the container adapts its height depending on the content (simple images in my case). And it does update on slide change.

The problem is that on first load the slide seems to miscalculate the height and makes it a square, ignoring the content height.

This are my dependencies:

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

This is the ponent:

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>
)

So, I'm using SwiperJs with autoheight. I expected that on slide change the container adapts its height depending on the content (simple images in my case). And it does update on slide change.

The problem is that on first load the slide seems to miscalculate the height and makes it a square, ignoring the content height.

This are my dependencies:

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

This is the ponent:

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>
)
Share Improve this question edited May 31, 2024 at 12:41 Sébastien Gicquel 4,3867 gold badges57 silver badges87 bronze badges asked Jun 21, 2022 at 17:59 Nuno LemosNuno Lemos 111 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

I added these two properties and it seems to work fine:

  observer: true,
  observeParents: true,

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744219681a4563720.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信