0

Before it is suggested, I have searched extensively for a solution and have not found one suitable based on my technical ability.

I need to be able to change the offset of this waypoint script to '-1' if it's going up and '0' if it's scrolling down.

$(document).ready(function(){
$('section').waypoint(function(direction) {
  var me = $(this); //added
  thisId = $(this).attr('id');
  $('ul.side_nav li').each(function(){
    var secondaryID = $(this).attr('class');
    if  ( secondaryID == thisId )
        {
            $('ul.side_nav li').removeClass('active');

            //added
            if(direction==='up'){
                me = $(this).prev();
            }

            //added
            if(!me.length){
                me = $(this);
            }

            $(this).addClass('active');

        }

    });

}); 

});

I have tried various things such as:

$(document).ready(function(){
$('section').waypoint(function(direction) {
  var me = $(this); //added
  thisId = $(this).attr('id');
  $('ul.side_nav li').each(function(){
    var secondaryID = $(this).attr('class');
    if  ( secondaryID == thisId )
        {
            $('ul.side_nav li').removeClass('active');

            //added
            if(direction==='up'){
                me = $(this).prev();
            }

            //added
            if(!me.length){
                me = $(this);
            }

            $(this).addClass('active');

        }

    });

}); 

$('section').waypoint(function(direction) {
    if (direction === 'down') {
    // Do stuff
    }
    }, {
    offset: '0'
    }).waypoint(function(direction) {
    if (direction === 'up') {
    // Do stuff
    }
    }, {
    offset: '-1'
    });

});

But have been unable to get a result...Again due to my lack of knowledge with JS, Jquery and Waypoint.js.

Any help would be gratefully received!

  • possible duplicate of [different offset for jquery waypoint "up" event](http://stackoverflow.com/questions/19181435/different-offset-for-jquery-waypoint-up-event) – imakewebthings Jan 29 '15 at 00:27
  • As mentioned above, this is slightly different as it involves the active class change...I've actually use some of the code you've mentioned above... – Unknownmale Jan 29 '15 at 14:07

0 Answers0