Add blur effect to element on scrollY past other div

I am trying to toggle a class on a div when the page is scrolled past another div (s1).

Whenever the page is scrolled to the specified div (s1), the class is not added to the blur div in the browser. I’ve tried numerous configurations of this code. This is the cleanest I’ve come up with but I’m unable to make it run.

The blur needs to be toggled via the ‘active’ class every time the top of s1 is passed, with the default being that ‘active’ is toggled off.

The blur itself works perfectly fine without JS logic.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> <div id="blur--linear-gradient"></div>
<main>
<div class="section-content s1"></div>
</main>
</code>
<code> <div id="blur--linear-gradient"></div> <main> <div class="section-content s1"></div> </main> </code>
    <div id="blur--linear-gradient"></div>
    <main>
        <div class="section-content s1"></div>
    </main>
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> #blur--linear-gradient {
display: none;
content: '';
position: absolute;
width: 100%;
height: 100%;
inset: 0;
z-index: -1;
-webkit-backdrop-filter: blur(10px);
-moz-filter: blur(10px);
-o-filter: blur(10px);
-ms-filter: blur(10px);
backdrop-filter: blur(10px);
-webkit-mask: linear-gradient(0deg, transparent, white 50%);
background: linear-gradient(hsl(var(--depth-HS) / 10%), hsl(var(--white) / 0%));
transition: all 300ms ease; /* for enabling class on scroll in JS */
}
#blur--linear-gradient.active {
display: block;
}
</code>
<code> #blur--linear-gradient { display: none; content: ''; position: absolute; width: 100%; height: 100%; inset: 0; z-index: -1; -webkit-backdrop-filter: blur(10px); -moz-filter: blur(10px); -o-filter: blur(10px); -ms-filter: blur(10px); backdrop-filter: blur(10px); -webkit-mask: linear-gradient(0deg, transparent, white 50%); background: linear-gradient(hsl(var(--depth-HS) / 10%), hsl(var(--white) / 0%)); transition: all 300ms ease; /* for enabling class on scroll in JS */ } #blur--linear-gradient.active { display: block; } </code>
    #blur--linear-gradient {
        display: none;
        content: '';
        position: absolute;
        width: 100%;
        height: 100%;
        inset: 0;
        z-index: -1;
        -webkit-backdrop-filter: blur(10px);
        -moz-filter: blur(10px);
        -o-filter: blur(10px);
        -ms-filter: blur(10px);
        backdrop-filter: blur(10px);
        -webkit-mask: linear-gradient(0deg, transparent, white 50%);
        background: linear-gradient(hsl(var(--depth-HS) / 10%), hsl(var(--white) / 0%));
        transition: all 300ms ease; /* for enabling class on scroll in JS */
    }
    
    #blur--linear-gradient.active {
        display: block;
    }
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> var headerContainer = document.getElementById('header-container');
var blurOverlay = document.getElementById('blur--linear-gradient');
var scrolledSection = document.getElementsByClassName('s1');
var scrolledSectionPos = scrolledSection.scrollTop - headerContainer.scrollHeight;
window.addEventListener('scroll', () => {
var scrollPos = window.scrollTop;
if (scrollPos >= scrolledSectionPos) {
blurOverlay.classList.toggle('active');
}
});
</code>
<code> var headerContainer = document.getElementById('header-container'); var blurOverlay = document.getElementById('blur--linear-gradient'); var scrolledSection = document.getElementsByClassName('s1'); var scrolledSectionPos = scrolledSection.scrollTop - headerContainer.scrollHeight; window.addEventListener('scroll', () => { var scrollPos = window.scrollTop; if (scrollPos >= scrolledSectionPos) { blurOverlay.classList.toggle('active'); } }); </code>
    var headerContainer = document.getElementById('header-container');
    var blurOverlay = document.getElementById('blur--linear-gradient');
    var scrolledSection = document.getElementsByClassName('s1');
    var scrolledSectionPos = scrolledSection.scrollTop - headerContainer.scrollHeight;
    
    window.addEventListener('scroll', () => {

        var scrollPos = window.scrollTop;
    
        if (scrollPos >= scrolledSectionPos) {
            blurOverlay.classList.toggle('active');
        }
    
    });

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật