Created
March 26, 2025 14:19
-
-
Save indikatordesign/f040ec516ae7ca0ced519bc120fff5a4 to your computer and use it in GitHub Desktop.
WWL TOC Blog Animation
This file contains hidden or 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
/* ----------------------------- TOC -------------------------- */ | |
/* --------------------------- jQuery ------------------------- */ | |
/* Im span wird "^" verwendet, mit einem Icon tauschbar ------- */ | |
/* In delta wird die genaue Zielposition festgelegt ----------- */ | |
$( '.toc-header' ).wrap( '<div class="toc wrap" />' ) | |
.after( '<span class="toc-item toc-icon header">^</span>' ); | |
$( '#toc-ol li, div.toc.wrap' ).on( 'click', function( e ) | |
{ | |
e.preventDefault(); | |
let delta = 15; | |
let t = $( this ); | |
let wid = ( $( window ).width() < 981 ? 0 : 90 ) + delta; | |
let elem, index; | |
if ( t.hasClass( 'wrap' ) ) | |
elem = $( '#toc' ); | |
else | |
{ | |
index = $( '#toc-ol li' ).index( t ); | |
elem = $( '.toc-header' ).eq( index ); | |
} | |
if ( elem.length < 1 ) | |
return false; | |
$( 'html, body' ).animate({ scrollTop: elem.offset().top - wid }, 200, 'swing', function() { return false; }); | |
}); | |
// Zur Nutzung in Vanilla JS bietet sich folgender Converter an: | |
// https://rakeshid03.github.io/Jquery-to-Javascript-Code-Converter/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment