Last active
February 25, 2016 16:51
-
-
Save pvlasov/df80b6a3147c763707a6 to your computer and use it in GitHub Desktop.
Extension for the DokuWiki Vector template to make the TOC remain visible when page scrolls. Put this file to the user directory of the Vector template and enable loading of user.js in the Configuration panel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function () { | |
var tocSelector = "#dw__toc"; | |
var top = jQuery(tocSelector).offset().top - parseFloat(jQuery(tocSelector).css('marginTop').replace(/auto/, 0)); | |
jQuery(window).scroll(function (event) { | |
// what the y position of the scroll is | |
var y = jQuery(this).scrollTop(); | |
var toc = jQuery(tocSelector); | |
if (y >= top) { | |
// if so, ad the fixed class | |
toc.css("position", "fixed"); | |
toc.css("top", "0"); | |
toc.css("right", "16px"); | |
toc.css("opacity", 0.7); | |
} else { | |
// otherwise remove it | |
toc.css("position", ""); | |
toc.css("top", ""); | |
toc.css("right", ""); | |
toc.css("opacity", 1); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment