aboutsummaryrefslogtreecommitdiff
path: root/divine/script.js
diff options
context:
space:
mode:
Diffstat (limited to 'divine/script.js')
-rw-r--r--divine/script.js143
1 files changed, 117 insertions, 26 deletions
diff --git a/divine/script.js b/divine/script.js
index ec6a283..958ff24 100644
--- a/divine/script.js
+++ b/divine/script.js
@@ -1,43 +1,134 @@
-// JavaScript to trigger scroll-based animations
-window.addEventListener("scroll", function () {
+// Updated JavaScript Code for Scroll Animations, FAQ Toggle, and Scroll-to-Top Button
+
+document.addEventListener("DOMContentLoaded", function () {
+ // Scroll-Based Animations with Debouncing
const elements = document.querySelectorAll(".hero-section, .features, .courses, .testimonials, .contact-section");
- elements.forEach(function (element) {
- if (element.getBoundingClientRect().top < window.innerHeight) {
- element.classList.add("visible");
- }
+ const handleScroll = () => {
+ elements.forEach((element) => {
+ if (element.getBoundingClientRect().top < window.innerHeight) {
+ element.classList.add("visible");
+ }
+ });
+ };
+
+ let debounceTimer;
+ window.addEventListener("scroll", () => {
+ clearTimeout(debounceTimer);
+ debounceTimer = setTimeout(handleScroll, 100);
});
-});
-document.addEventListener("DOMContentLoaded", function() {
+ // FAQ Section Toggle
const faqItems = document.querySelectorAll(".faq-item");
- faqItems.forEach(item => {
- item.querySelector(".faq-question").addEventListener("click", () => {
+ faqItems.forEach((item) => {
+ const question = item.querySelector(".faq-question");
+ question.setAttribute("tabindex", "0"); // Make it keyboard accessible
+
+ const toggleAnswer = () => {
item.classList.toggle("active");
+ };
+
+ question.addEventListener("click", toggleAnswer);
+ question.addEventListener("keydown", (e) => {
+ if (e.key === "Enter" || e.key === " ") {
+ toggleAnswer();
+ e.preventDefault(); // Prevent page scroll on space key
+ }
});
});
-});
-// Get the button
-const scrollToTopButton = document.getElementById("scroll-to-top");
+
+ // Scroll-to-Top Button
+ const scrollToTopButton = document.getElementById("scroll-to-top");
-// When the user scrolls down 100px from the top of the document, show the button
-window.onscroll = function() {
- if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
- scrollToTopButton.style.display = "block";
- } else {
- scrollToTopButton.style.display = "none";
- }
-};
+ const handleScrollButtonVisibility = () => {
+ scrollToTopButton.style.display = window.scrollY > 100 ? "block" : "none";
+ };
-// When the user clicks on the button, scroll to the top of the document
-scrollToTopButton.addEventListener("click", function() {
- window.scrollTo({
- top: 0,
- behavior: "smooth" // Smooth scroll effect
+ window.addEventListener("scroll", handleScrollButtonVisibility);
+
+ scrollToTopButton.addEventListener("click", () => {
+ window.scrollTo({
+ top: 0,
+ behavior: "smooth",
+ });
});
+
+ // Prevent button visibility during downward animations
+ let isScrolling = false;
+ const throttleScrollHandler = () => {
+ if (!isScrolling) {
+ window.requestAnimationFrame(() => {
+ handleScrollButtonVisibility();
+ isScrolling = false;
+ });
+ }
+ isScrolling = true;
+ };
+
+ // Initial Trigger for Scroll Animations and Button Visibility
+ handleScroll();
+ handleScrollButtonVisibility();
+});
+
+
+
+
+
+
+
+
+
+
+
+
+
+document.addEventListener("DOMContentLoaded", () => {
+ const sections = document.querySelectorAll(".features, .courses, .testimonials, .faq");
+
+ const observer = new IntersectionObserver(
+ (entries, observer) => {
+ entries.forEach((entry) => {
+ if (entry.isIntersecting) {
+ entry.target.classList.add("animate");
+ observer.unobserve(entry.target); // Stop observing once animated
+ }
+ });
+ },
+ { threshold: 0.1 }
+ );
+
+ sections.forEach((section) => observer.observe(section));
});
+
+
+
+
+
+
+
+// Function to check if an element is in the viewport
+function isInViewport(element) {
+ const rect = element.getBoundingClientRect();
+ return rect.top <= window.innerHeight && rect.bottom >= 0;
+}
+
+// Scroll event listener
+function handleScroll() {
+ const elements = document.querySelectorAll('.feature-item, .course-item, .testimonial, .faq-item');
+ elements.forEach((el) => {
+ if (isInViewport(el)) {
+ el.classList.add('animate');
+ }
+ });
+}
+
+// Attach event listener to the window
+window.addEventListener('scroll', handleScroll);
+
+// Trigger animation on load (in case elements are already in view)
+handleScroll(); \ No newline at end of file