javascript - react : How can I position the loading component so it is in the center of the image

标签 javascript html css reactjs

这是代码和演示:

https://codesandbox.io/s/sparkling-silence-7cv3l

https://7cv3l.csb.app/

我使用 react-image-enlarger 组件来缩放图像,例如 Medium。它有一个 API,renderLoading 用于在下载放大图像时呈现加载组件。所以我为加载组件导入了react-loading

相关代码片段:

<div style={{ margin: "0.25rem" }}>
      <Image
        style={{ width: "200px", height: "auto" }}
        zoomed={zoomed}
        src={src}
        enlargedSrc={{}}
        onClick={() => setZoomed(true)}
        onRequestClose={() => setZoomed(false)}
        renderLoading={<ReactLoading type={"cylon"} color="black" />}
      />
    </div>

现在加载动画出现在图像下方。

enter image description here

但是我想让加载动画位于图像的中心并且应该对图像应用滤镜以使其更暗(可能是亮度(0.7);)

我认为这不是一项微不足道的工作,因为每张图片都有自己的高度和宽度,而且我不是很擅长 CSS,因此非常感谢任何帮助。

最佳答案

尝试使用此 CSS 代码将加载器的位置设置在每张图片的中心。

img.EnlargedImage__Image + div {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
    background-color: rgba(255, 255, 255, 0.75);
    height: 100% !important;
    width: 100% !important;
}
img.EnlargedImage__Image + div svg {
    height: 64px;
    width: 64px;
    margin: auto;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
}

关于javascript - react : How can I position the loading component so it is in the center of the image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57850161/

相关文章:

javascript - 无法在移动 Safari 中的带有子项的 tabindexed 元素上设置 focus()?

javascript - 从 JSON 属性加载 HTML img 元素的图像,而 URL 不能直接访问

jquery - 使用 jquery 使用父元素的属性设置子元素 attr

css - 当元素到达底部边缘时设置不透明度

css - 旋转html正文背景

javascript - 如何使 <button> 标记中的 location.href =' ' 仅在输入有效时才起作用?

javascript - 重用 AngularJS Controller 逻辑

javascript - 将表单数据传递给 python

html - 将 3 张图片与页面的其余部分对齐

html - Chrome 中的嵌套 Div 出现故障