0

I have a website http://www.mitchellfinlay.co.uk/newlake/magazines.html

It utilizes a curtain effect, each li element is revealed on scroll or automatically when links are clicked at the top... tempus...talkbusiness etc.

What I would like to do is set the class of the link to 'current' when the user either scrolls to that curtain the link is anchored to.

This needs to happen as the user is scrolling or when the auto scroll has stopped on that page.

Is this achievable?

Alex Schimp
  • 2,295
  • 1
  • 20
  • 35
finlamit
  • 17
  • 2

2 Answers2

0

This should iterate over links in the header, remove the class current from each of them, and add it to the clicked link:

$(document).on('click', '#headerLinks a', function() {
    $("#headerlinks a").removeClass("current");
    $(this).addClass("current");
});

As for the scrolling, you can use element.posistion() and window.scrollTop() to figure out what element is on top of the screen. I've made a demo in this fiddle. You'll have to adapt it for your needs, but it shows the basic concept.

Jørgen R
  • 9,179
  • 7
  • 36
  • 56
0

For your second question on comments:

You can strip anchor with this variable and check what's left behind.

Example:

$('#headerlinks a').click(function(){
   var anchor = document.location.hash;
   if ( anchor === '#myContent1' ) { //this can be href from ur a.
     $('.allContents').hide();
     $('#myContent1').show();
   }
});
Alex Schimp
  • 2,295
  • 1
  • 20
  • 35
Barlas Apaydin
  • 6,794
  • 10
  • 50
  • 81