Differenze tra le versioni di "MediaWiki:Common.js"
| Riga 2: | Riga 2: | ||
document.addEventListener('DOMContentLoaded', function() { | document.addEventListener('DOMContentLoaded', function() { | ||
| − | let headerHeight = document.querySelector('header').offsetHeight; | + | let headerHeight = document.querySelector('header').offsetHeight; |
document.querySelectorAll('a[href^=\'#\']').forEach(anchor => { | document.querySelectorAll('a[href^=\'#\']').forEach(anchor => { | ||
anchor.addEventListener('click', function(e) { | anchor.addEventListener('click', function(e) { | ||
| Riga 8: | Riga 8: | ||
let target = document.querySelector(this.getAttribute('href')); | let target = document.querySelector(this.getAttribute('href')); | ||
if (target) { | if (target) { | ||
| − | let targetPosition = target.offsetTop - headerHeight + 500; | + | let targetPosition = target.offsetTop - headerHeight + 500; |
window.scrollTo({ top: targetPosition, behavior: 'smooth' }); | window.scrollTo({ top: targetPosition, behavior: 'smooth' }); | ||
} | } | ||
Versione delle 08:40, 16 gen 2025
/* Il codice JavaScript inserito qui viene caricato da ciascuna pagina, per tutti gli utenti. */
document.addEventListener('DOMContentLoaded', function() {
let headerHeight = document.querySelector('header').offsetHeight;
document.querySelectorAll('a[href^=\'#\']').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
let target = document.querySelector(this.getAttribute('href'));
if (target) {
let targetPosition = target.offsetTop - headerHeight + 500;
window.scrollTo({ top: targetPosition, behavior: 'smooth' });
}
});
});
});