MediaWiki:SupportPage.js: Difference between revisions

Content deleted Content added
minor cleanup
No edit summary
Line 20:
topMenu = $('#toc > ul'),
menuItems = topMenu.find('a'), // All TOC links
scrollItems = $('.sp-content .mw-headline');, // Anchors corresponding to TOC links
scrollOffset = 16, // Offset in px
scrollDuration = 500; // in ms
 
/* Bind click handler to menu items so we can get a fancy scroll animation */
menuItems.click(function(e){
var id = $(this).attr('href').replace('#', ''),;
var offsetTop = $( document.getElementById(id) ).offset().top;
$('html, body').stop().animate({
scrollTop: offsetTop - scrollOffset
}, 850scrollDuration);
e.preventDefault();
});
Line 34 ⟶ 36:
/* Highlighting current section in TOC */
$(window).scroll(function(){
var fromTop = $(this).scrollTop(); // Get container scroll position
var fromTop = $(this).scrollTop();
 
// Get id of current scroll item
var cur = scrollItems.map(function(){
if ( $(this).offset().top < fromTop ) {
return this;
});
});
// Get the id of the current element
cur = cur[cur.length-1];