首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swiper.js响应不适用于breakPoints

Swiper.js响应不适用于breakPoints
EN

Stack Overflow用户
提问于 2022-11-26 21:47:00
回答 1查看 27关注 0票数 0

我尝试了这个非常基本的Swiper示例来使用Swiper库检查响应,但问题是当我调整屏幕大小时,没有得到断点指定的slidesPerView (经常是一个slidePerView)。

以下是代码:

代码语言:javascript
复制
import React from 'react'
import {Swiper , SwiperSlide} from 'swiper/react'
import 'swiper/css'

const SwiperCard =()=>{
return(
        <Swiper

            breakPoints={{
            0: {slidesPerView: 1},
            480: {slidesPerView: 2,
                   spaceBetween: 16},
            768: {slidesPerView: 4,
                   spaceBetween: 16},
            1024:{slidesPerView: 8,
                   spaceBetween: 16}
            }}
        >
        <SwiperSlide>
            <div style={{backgroundColor: 'red'}}>slide1</div>
        </SwiperSlide>
        <SwiperSlide>
            <div style={{backgroundColor: 'red'}}>slide2</div>
        </SwiperSlide>
        <SwiperSlide>
            <div style={{backgroundColor: 'red'}}>slide3</div>
        </SwiperSlide>
        <SwiperSlide>
            <div style={{backgroundColor: 'red'}}>slide4</div>
        </SwiperSlide>
        <SwiperSlide>
            <div style={{backgroundColor: 'red'}}>slide5</div>
        </SwiperSlide>
        <SwiperSlide>
            <div style={{backgroundColor: 'red'}}>slide6</div>
        </SwiperSlide>
        <SwiperSlide>
            <div style={{backgroundColor: 'red'}}>slide7</div>
        </SwiperSlide>
        <SwiperSlide>
            <div style={{backgroundColor: 'red'}}>slide8</div>
        </SwiperSlide>
        </Swiper>


)
}
export default SwiperCard

the App.js

代码语言:javascript
复制
import './App.css';
import SwiperCard from './component/SwiperCard'
function App() {
  return (
    <div className="App">

        <SwiperCard />
    </div>
  );
}

export default App;

我希望我得到一个答案,因为我想把它包括在我的反应项目中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-27 08:04:08

道具的名字错了。带有小字母"p“的breakpoints是正确的。

它的文档在这里:https://swiperjs.com/swiper-api#param-breakpoints

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74585819

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档