改变基于变量的React Simple Image Slider中的高度和宽度数值

huangapple go评论60阅读模式
英文:

change height, width values based on variable in react-simple-image-slider

问题

我正在使用 React 实现类似图像幻灯片的东西使用了 npm  - react-simple-image-slider

实现如下 

export default function Home(){

    const images = [
        { url: "images/1.jpg" },
        { url: "images/2.jpg" },
        { url: "images/3.jpg" },
      ];
    const open = true;
    
        <SimpleImageSlider
                      width={`${open ? 896 : 880}`}
                      height={`${open ? 430 : 440}`}
                      images={images}
                      showBullets={true}
                      showNavs={true}
                    />
}
我尝试根据一个变量改变高度和宽度但这并没有加载任何内容页面是空白的我是否遗漏了什么请帮忙
英文:

i am implementing an image slideshow kind of thing in react using npm package - react-simple-image-slider.

implementation->

export default function Home(){

const images = [
    { url: &quot;images/1.jpg&quot; },
    { url: &quot;images/2.jpg&quot; },
    { url: &quot;images/3.jpg&quot; },
  ];
const open = true;

    &lt;SimpleImageSlider
                  width={`${open ? 896 : 880}`}
                  height={`${open ? 430 : 440}`}
                  images={images}
                  showBullets={true}
                  showNavs={true}
                /&gt;
}

i am trying to change height, width based on a variable. but this doesnt load anything. page is empty. am i missing something. please help.

答案1

得分: 0

你可以尝试直接传入数值,并按照以下代码进行条件设置,我认为它会按预期工作。

&lt;SimpleImageSlider
  width={open ? 896 : 880}
  height={open ? 430 : 440}
  images={images}
  showBullets={true}
  showNavs={true}
/&gt;
英文:

you can try passing in numeric values directly and conditionally set them like follow code, I think it will work as expected.

&lt;SimpleImageSlider
  width={open ? 896 : 880}
  height={open ? 430 : 440}
  images={images}
  showBullets={true}
  showNavs={true}
/&gt;

huangapple
  • 本文由 发表于 2023年2月16日 17:22:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75470128.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定