【问题标题】:react js carousel and positions反应 js 轮播和位置
【发布时间】:2019-12-17 05:57:36
【问题描述】:

您好,我有一个轮播,但根据我的轮播的大小,我无法将图像 100% 保留

const ImageCarousel = () => (
  <CarouselProvider
  totalSlides={3}
  naturalSlideWidth={1}
  naturalSlideHeight={1.25}
  dragEnabled={false}
  touchEnabled={false}
  style={{ height: "500",position: "relative"}}
  >
    <Slider style={{maxHeight:'500px', width:'100%'}}>
      <Slide tag="a" index={0}>
        <Image  src="https://lorempixel.com/800/800/cats/0" />
      </Slide>
      <Slide tag="a" index={1}>
        <Image src="https://lorempixel.com/800/800/cats/1" />
      </Slide>
      <Slide tag="a" index={2}>
        <Image src="https://lorempixel.com/800/800/cats/2" />
      </Slide>
    </Slider>
    <Container style={{position: 'relative', backgroundColor:'#000'}}>
    <ButtonBack style={{position: 'absolute', transform: 'translate(-50%,-50%)', backgroundColor: 'transparent', border: 0}}><Icon fitted name='arrow right' size='big' /></ButtonBack>
    <ButtonNext style={{position: 'absolute', transform: 'translate(-50%,-50%)', backgroundColor: 'transparent', border: 0}}><Icon fitted name='arrow left' size='big' /></ButtonNext>
    </Container>
  </CarouselProvider>
);

现在我有了这个:

【问题讨论】:

    标签: css reactjs


    【解决方案1】:

    嗨,这个容器应该有一个宽度。

    1- 在 ImageCarousel.js 的同一文件夹中创建一个名为“ImageCarousel.css”的 css 文件,并将代码放在下面:

    .innterClass {
        height: 500px !important;
    }
    

    2- 导入代码ImageCarousel.js

    import "./ImageCarrousel.css";
    

    3- 这是您的 ImageCarousel 组件中应包含的代码:

    const ImageCarousel = () => (
      <CarouselProvider
      totalSlides={3}
      naturalSlideWidth={1}
      naturalSlideHeight={1.25}
      dragEnabled={false}
      touchEnabled={false}
      style={{ height: "500",position: "relative"}}
      >
        <Slider style={{maxHeight:'500px'}}>
          <Slide innerClassName="innterClass" index={0}>
            <Image style={{objectFit: "cover"}}  src="https://lorempixel.com/800/800/cats/0" />
          </Slide>
          <Slide innerClassName="innterClass" index={1}>
            <Image style={{objectFit: "cover"}}  src="https://lorempixel.com/800/800/cats/1" />
          </Slide>
          <Slide innerClassName="innterClass" index={2}>
            <Image style={{objectFit: "cover"}}  src="https://lorempixel.com/800/800/cats/2" />
          </Slide>
        </Slider>
        <ButtonBack style={{position: 'absolute',top:'50%',left:'30%' ,transform: 'translate(-50%,-50%)', backgroundColor: 'transparent', border: 0}}><Icon fitted name='arrow right' size='big' /></ButtonBack>
        <ButtonNext style={{position: 'absolute', right:'30%', top: "50%", transform: 'translate(-50%,-50%)', backgroundColor: 'transparent', border: 0}}><Icon fitted name='arrow left' size='big' /></ButtonNext>
    
      </CarouselProvider>
    );
    

    【讨论】:

    • 关于图片,我的身高无法完整显示,您能帮帮我吗?
    • 是的......你有它在 github 上还是你发布在某个地方我可以看一下?
    • 是的:github.com/lostspirit1/carousel / 我在组件/标题和/资产/组件/轮播上的轮播
    • 是的。您必须剪切图像才能用作“横幅”(半屏)。此外,您可以使用 div 并将它们设置为背景图像。因此,您可以使用名为 background-size 的属性并将其设置为覆盖。还。别忘了把顶部:50%;在您的
    • 所以我必须带上我的 并添加一个带有图像的 div 并使用 backgroundsize?
    猜你喜欢
    • 2022-11-12
    • 2021-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 2019-09-03
    • 2020-04-26
    • 1970-01-01
    相关资源
    最近更新 更多