MediaWiki

Foreground.js: Difference between revisions

From Grouse House Wiki

No edit summary
No edit summary
 
(47 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Collapsible Headers */
/* Scroll to top and sidebar logo */


var coll = document.getElementsByClassName("c-header");
var scrollbutton = document.getElementById("scrollToTop");
var i;
var sidebarlogo = document.getElementById("sidebarlogo");


var coll2 = document.getElementsByTagName("h3");
window.onscroll = function() {scrollFunction()};
var i2;


for (i = 0; i < coll.length; i++) {
function scrollFunction() {
   coll[i].addEventListener("click", function() {
   if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
     this.classList.toggle("active");
     scrollbutton.style.display = "block";
    var content = this.nextElementSibling;
     sidebarlogo.style.display = "block";
     if (content.style.display === "block") {
  } else {
      content.style.display = "none";
    scrollbutton.style.display = "none";
     } else {
     sidebarlogo.style.display = "none";
      content.style.display = "block";
   }
    }
   });
}
}


for (i2 = 0; i2 < coll2.length; i2++) {
function topFunction() {
   coll2[i2].addEventListener("click", function() {
   document.body.scrollTop = 0;  
    this.classList.toggle("active");
  document.documentElement.scrollTop = 0;
    var content = this.nextElementSibling;
    if (content.style.display === "block") {
      content.style.display = "none";
    } else {
      content.style.display = "block";
    }
  });
}
}

Latest revision as of 01:43, 1 April 2024

/* Scroll to top and sidebar logo */

var scrollbutton = document.getElementById("scrollToTop");
var sidebarlogo = document.getElementById("sidebarlogo");

window.onscroll = function() {scrollFunction()};

function scrollFunction() {
  if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
    scrollbutton.style.display = "block";
    sidebarlogo.style.display = "block";
  } else {
    scrollbutton.style.display = "none";
    sidebarlogo.style.display = "none";
  }
}

function topFunction() {
  document.body.scrollTop = 0; 
  document.documentElement.scrollTop = 0;
}