מדיה ויקי:Common.js: הבדלים בין גרסאות בדף
קפיצה לניווט
קפיצה לחיפוש
אין תקציר עריכה |
אין תקציר עריכה |
||
| שורה 1: | שורה 1: | ||
$(document).ready(function() { | $(document).ready(function() { | ||
const toc = | const $toc = $('#toc'); | ||
const headers = | const $headers = $('h2, h3'); | ||
const tocLinks = | const $tocLinks = $('#toc a'); | ||
function updateTocPosition() { | |||
const headerHeight = $('#firstHeading').outerHeight(); | const headerHeight = $('#firstHeading').outerHeight(); | ||
if ($(window).scrollTop() > headerHeight) { | if ($(window).scrollTop() > headerHeight) { | ||
toc. | $toc.css('top', '0px'); | ||
} else { | } else { | ||
toc. | $toc.css('top', '220px'); | ||
} | } | ||
} | } | ||
function highlightCurrentSection() { | |||
let currentSection = ''; | let currentSection = ''; | ||
$headers.each(function() { | |||
if ($(window).scrollTop() >= $(this).offset().top - 100) { | |||
currentSection = this.id; | |||
if ($(window).scrollTop() >= | |||
currentSection = | |||
} | } | ||
}); | }); | ||
tocLinks. | $tocLinks.removeClass('toc-highlight'); | ||
$tocLinks.each(function() { | |||
if ( | if ($(this).attr('href').slice(1) === currentSection) { | ||
$(this).addClass('toc-highlight'); | |||
} | } | ||
}); | }); | ||
} | |||
$(window).on('scroll', function() { | |||
updateTocPosition(); | |||
highlightCurrentSection(); | |||
}); | }); | ||
updateTocPosition(); // קריאה ראשונית כדי לקבוע את המיקום בתחילת הטעינה | |||
}); | }); | ||
גרסה מ־18:24, 3 בפברואר 2025
$(document).ready(function() {
const $toc = $('#toc');
const $headers = $('h2, h3');
const $tocLinks = $('#toc a');
function updateTocPosition() {
const headerHeight = $('#firstHeading').outerHeight();
if ($(window).scrollTop() > headerHeight) {
$toc.css('top', '0px');
} else {
$toc.css('top', '220px');
}
}
function highlightCurrentSection() {
let currentSection = '';
$headers.each(function() {
if ($(window).scrollTop() >= $(this).offset().top - 100) {
currentSection = this.id;
}
});
$tocLinks.removeClass('toc-highlight');
$tocLinks.each(function() {
if ($(this).attr('href').slice(1) === currentSection) {
$(this).addClass('toc-highlight');
}
});
}
$(window).on('scroll', function() {
updateTocPosition();
highlightCurrentSection();
});
updateTocPosition(); // קריאה ראשונית כדי לקבוע את המיקום בתחילת הטעינה
});