【问题标题】:Why lazy loading sections creates overflow_x为什么延迟加载部分会创建溢出_x
【发布时间】:2022-01-22 03:44:14
【问题描述】:

您好,我有一个问题,我正在尝试使我的页面 RWD,但问题是当 interSectionObserver 加载部分时它会创建溢出_x,它会导致页面上的定位消失,但是当它到达页面末尾时,一切都已修复.更多代码可以在我的 github 上找到,但我不确定我是否有权粘贴它。

CSS

.section {
   transition: opacity 1s, transform 1s;
}
.hidden-section {
    opacity: 0;
    transform: translateY(7rem);
}

JS:

        
        _revealSection() {
                const sections = document.querySelectorAll('.section');
                const options = {
                    root: null,
                    threshold: 0.15,
                    rootMargin: "0px",
                }
        
                const showSection = ((entries, observer) => {
                    const [entry] = entries;
                    if (!entry.isIntersecting) return 
                    entry.target.classList.toggle('hidden-section')
                    observer.unobserve(entry.target)
                    
                })
        
                const sectionFadeIn = new IntersectionObserver(showSection, options);
        
                sections.forEach(sec => {
                    sec.classList.add('hidden-section')
                    sectionFadeIn.observe(sec)
                } )
            }

HTML:

    <section class="section" id="section--5">
                <div class="contact">
                    <h1 class="contact__header">Are you ready for an new experience?</h1>
                    <button class=" modal-button contact__button" data-but="4">contact us</button>
                </div>

【问题讨论】:

  • 请同时添加一些相关的 HTML。没有它,我们无法进行故障排除。请阅读how to create a minimal reproducible example
  • 可能只是我,但RWD是什么?
  • HTMl 的问题是我应该放整个文件,因为它是关于部分的,但我肯定会尝试放一些。

标签: javascript sass


【解决方案1】:

好的,问题出在 html 和 body 标记中。

html, body {
width: 100;
overflow-x: hidden;
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-08
    • 1970-01-01
    • 2014-12-20
    • 2010-09-07
    • 2018-07-05
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    相关资源
    最近更新 更多