我的项目主页有一个图片库,每X秒自动滚动一次. 在Chrome和Firefox上,一切都很好,但在Safari上,只有第一张图片显示得很好,其他的都是空白幻灯片.

这里是主页组件:

import { useEffect, useState, useRef } from 'react'

import './home.styles.scss'

const galleriaDiImmagini = [
    'https://i.ibb.co/LCzz4P4/1.webp',
    'https://i.ibb.co/txwnt76/2.webp',
    'https://i.ibb.co/XCHDFpx/3.webp',
    'https://i.ibb.co/S6F1rtc/4.webp',
    'https://i.ibb.co/P5GwHPz/5.webp'
]

const delay = 6000
 
const HomePage = () => {
    const [index, setIndex] = useState(0)
    const timeoutRef = useRef(null)

    const resetTimeout = () => timeoutRef.current ? clearTimeout(timeoutRef.current) : null

    useEffect(() => {
        resetTimeout()
        timeoutRef.current = setTimeout(
            () => 
                setIndex(prevIndex =>
                    prevIndex === galleriaDiImmagini.length - 1 ? 0 : prevIndex + 1
                ),
            delay
        )
      
        return () => {
            resetTimeout()
        }
    }, [index]) 

    return (
        <div className='homepage'> 
            <div 
                className='slide-container'
                style={{ transform: `translate3d(${-index * 100}%, 0, 0)` }}
            >
            {
                galleriaDiImmagini.map((img, i) => (
                    <div 
                        key={ i }
                        className='slide'
                        style={{
                            'background': `url(${img}) no-repeat center center fixed`
                        }}                            
                    >
                    </div>
                ))
            }
            </div>
            <div className="punti-container">
                {galleriaDiImmagini.map((_, i) => (
                    <div
                        key={i}
                        className={`punto${index === i ? " active" : ""}`}
                        onClick={() => {
                            setIndex(i);
                        }}
                    >
                    </div>
                ))}
            </div>          
        </div>
    )
}

export default HomePage

和风格:

$colore-tosto: #2FA7CF;

.homepage {
    position: relative;
    overflow: hidden;
    height: 100vh;

    .slide-container {
        height: 100%;
        width: 100%;        
        position: relative;
        white-space: nowrap;
        -webkit-transition: transform 1000ms ease-in-out;
        -moz-transition: transform 1000ms ease-in-out;
        -o-transition: transform 1000ms ease-in-out;        
        transition: transform 1000ms ease-in-out;

        .slide {
            display: inline-block;
            height: 100%;
            width: 100%;
            background-size: contain; 
            -webkit-background-size: contain;
            -moz-background-size: contain;
            -o-background-size: contain;                
          }
    }

    .punti-container {
        width: 100%;
        text-align: center;
        position: absolute;
        top: 75%;

        .punto {
            display: inline-block;
            height: 20px;
            width: 20px;
            border-radius: 50%;
            background-color: rgba($color: #ffff, $alpha: 0.5);
            border: 2.5px solid $colore-tosto;
            margin: 15px;

            &:hover {
                cursor: pointer;
                background-color: rgba($color: #ffff, $alpha: 0.9);
            }

            &.active {
                background-color: white;
            }           
        }       
    }

    @media only screen and (max-width: 730px) {

        .punti-container {
            top: 80%;

            .punto {
                height: 17px;
                width: 17px;
                border-width: 1.5px;
                margin: 10px;
            }
        }

        .slide-container {

            .slide {
                background-size: auto 100% !important;
            }
        }
    }      
}

here个网站的现场视频. 我要提前感谢任何试图帮助我的人.

推荐答案

你需要删除在Safari上不支持的background-attachment : fixed,在这里勾选Can I use,background css键的最后一个参数是附件

Html相关问答推荐

XPATH text()函数遇到困难

我的表的第一列似乎是推其他2列到右边,我不能改变它

如何在不影响子列表的情况下在HTML(OL Li)上同时加数字和列表?

自动字间距以适应行CSS

将网格包装在css中

如何使用css为动态用户输入矩阵添加背景色?

页脚与主要内容重叠

MatSnackBar: colored颜色 不起作用

Style=背景图像URL引用变成&;Quot;

在 HTML 视频上环绕文本叠加

如何在黑暗模式切换中添加图标

为什么即使我点击其他地方,我的 contenteditable="true" 也会被激活?

Flex布局中,当父元素高度较高时,交叉轴上出现额外的空白问题.

如何使容器的大小适合其 position:absolute; 子元素的大小

对齐页面左侧的单选按钮

ul li 右侧的 Bootstrap 加载微调器

导航丸被选中(活动),但内容未显示.怎么会?

辅助功能:alt 或 alt="" 用于装饰图像

禁用的 Select 标签没有在 chrome 上的 css 中指定的 colored颜色

我的卡片内容无法在 bootstrap 5 中正确居中