Aktuellen Abschnitt mit JavaScript erkennenHTML

HTML-Programmierer
Anonymous
 Aktuellen Abschnitt mit JavaScript erkennen

Post by Anonymous »

Ich arbeite an einer einseitigen Website. Ich habe ein festes Menü in reinem HTML, hier ist der Code:

Code: Select all


WM Flying

[url=#section1]Home[/url]
[url=#section2]About[/url]
[url=#section3]Portfolio[/url]
[url=#section4]The team[/url]
[url=#section5]Contact[/url]















Dann möchte ich den Abschnitt „aktuell“ ändern, um einen anderen Stil auf das ausgewählte Menü anzuwenden. Hier ist mein JavaScript:

Code: Select all

var currentSection = "section1";

function change($section){
$('nav.menu a').removeClass('current');
currentSection = $section.attr('id');
$('body').removeClass();
$('body').addClass( $section.attr('id') + '-visible' );
$('.target-'+currentSection).addClass('current');
}
Dann wende ich einfach ein CSS wie dieses an:

Code: Select all

nav a.current, nav a:hover{
background: #F0F0F0;
color: #E46C51;
}
Um die Funktion aufzurufen, verwende ich Folgendes:

Code: Select all

$("#main section").waypoint( function( direction ) {
if( direction === 'down' ) {
change( $( this ) );
}
}, { offset: '20%' } ).waypoint( function( direction ) {
if( direction === 'up' ) {
change( $( this ) );
}
}, { offset: '-20%' } );
Aber es scheint nicht zu funktionieren. Kann mir jemand helfen?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post