MediaWiki:Common.js: Difference between revisions

From Geeetech Wiki
Jump to navigation Jump to search
Created page with "var div = document.getElementById("toc"); var toc_height = document.getElementById("toc").offsetHeight; var toc_to_top = document.getElementById("bodyContent").offsetTop; var..."
(No difference)

Revision as of 07:13, 13 September 2022

var div = document.getElementById("toc");
var toc_height = document.getElementById("toc").offsetHeight;
var toc_to_top = document.getElementById("bodyContent").offsetTop;
var toc_scroll_top = toc_height + toc_to_top + 20;

window.onscroll = function() {
  var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  if(scrollTop > toc_scroll_top){
    document.getElementById('toc').style.position = 'fixed';
  } else {
    document.getElementById('toc').style.position = '';
  }
}