Skip to content

Commit

Permalink
Fixed page empty on load #30 (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anjaliavv51 authored Jan 8, 2025
2 parents 50d8eb2 + ff4d679 commit 14dc01c
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions scrollscript.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
window.onload = function(){
document.getElementById("hero").classList.add('scrolled')
}


document.addEventListener("scroll", function() {
const heroSection = document.querySelector(".hero");
const heroH2 = document.querySelector(".hero h2");
const heroP = document.querySelector(".hero p.subtitle");

const wisdomContent = document.querySelector(".wisdom-section .wisdom-content");
const wisdomImage = document.querySelector(".wisdom-image");

const scrollPosition = window.scrollY + window.innerHeight;

// Check if the user has scrolled to the hero section and apply/remove the scrolled class
if (scrollPosition > heroSection.offsetTop + heroSection.offsetHeight / 3) {
heroSection.classList.add("scrolled");
heroH2.classList.add("scrolled");
heroP.classList.add("scrolled");
} else {
heroSection.classList.remove("scrolled");
heroH2.classList.remove("scrolled");
heroP.classList.remove("scrolled");
}

// Check if the user has scrolled to the wisdom section content and apply/remove the scrolled class
if (scrollPosition > wisdomContent.offsetTop + wisdomContent.offsetHeight / 3) {
wisdomContent.classList.add("scrolled");
Expand Down

0 comments on commit 14dc01c

Please sign in to comment.