0

I was taking a look at ScrollMagic's documentation. I see that I can use a callback function to change the scroll behavior as shown below:

controller.scrollTo(function (newScrollPos) {
    $("body").animate({scrollTop: newScrollPos});
});

Is there a way to pass more parameters to this function? For some specific links/anchors, I would like to use an offset. I have not been able to figure out how to pass more parameters, or how to get the ScrollTarget from within the callback.

1 Answers1

0

this function is only meant to receive a number as all it should do is create a custom scroll behavior moving to that number.

You can however reference the controller inside the callback using this.

The functionality of converting element or scene positions to scroll positions (if you supply an element or a scene to controller.scrollTo) is handled before the custom callback is even called.

So to get it to work with certain offsets for specific cases, you'll need to handle that before the function is actually called.
For example in your click handler.

Here's some pseudocode:

anchor.on(click, function() {
    if (this is an exception) {
         var customPos = targetElement.offset().top + offset;
         controller.scrollTo(customPos);
    } else {
         controller.scrollTo(targetElement);
    }
});
Jan Paepke
  • 1,997
  • 15
  • 25
  • 1
    That makes perfect sense. Thank you for taking the time to explain it. –  Mar 16 '15 at 14:46