imakewebthings/jquery-waypoints — Issue #33: Trigger issue
Author: anarcho117
Created: 2011-12-14 14:13:03+00:00
State: open

Hi there,

Here's my issue:

Much like the nav on the Waypoints page (http://imakewebthings.github.com/jquery-waypoints/) I have a navigation element with active states triggering when the corresponding div IDs are reached.

However, I've also added in a couple of other waypoints that trigger other effects. The problem occurs when scrolling back up, the code 'if (direction === "up") {$active = $active.prev();}' includes the additional waypoints and triggers the nav active links in the wrong place.

Hope this makes sense?

Here's, my full script - any advice would be hugely appreciated! Thanks, Matt

$('.slide').waypoint();

$('body').delegate('.slide', 'waypoint.reached', function(event, direction) {

var $active = $(this);

if (direction === "up") {
$active = $active.prev();
}
if (!$active.length) $active.end();

$('.link-active').removeClass('link-active');
$('a[href=#'+$active.attr('id')+']').addClass('link-active');

});

$('#homec').waypoint(function(event, direction) {
if (direction === 'down') {
$('.logo').addClass('fout');
}
else {
$('.logo').removeClass('fout');
}
},{
offset: -100
});

$('.twocol').waypoint(function(event, direction) {

if (direction === 'down') {
$(this).animate({opacity: 0.2}, 300);
}
else {
$(this).animate({opacity: 1}, 300);
}
},{
offset: -100
});