cup_of
cup_of

Reputation: 6697

Custom waypoint function error

Hello I am writing a custom waypoint function and I am getting an error and was wondering if someone could help me out. The function is using waypoints.js

http://imakewebthings.com/waypoints/

Here is the code I have so far

var waypoint = function(triggerElement, animatedElement, className, offsetVal) {
    element: document.getElementById(triggerElement);
    handler: function(direction) {
        if (direction === 'down') {
            animatedElement.addClass(className);
            this.destroy();
        }
        else {

        }
    };
    offset: offsetVal;
};

//Trigger Elements
var section2 = jQuery('#section-2');

//Waypoint Instances
waypoint(section2, "section-2-orange-dot", "section-2-orange-dot-active", 500);

I am getting an error at the third line

handler: function(direction) {

"Uncaught SyntaxError: Unexpected token ("

Thanks!

Upvotes: 0

Views: 253

Answers (1)

mjw
mjw

Reputation: 1206

You need to use commas to delimit the function arguments, not semicolons. You are also passing in the selected jQuery object as triggerElement, so you don't need the getElementById:

function waypoint (triggerElement, animatedElement, className, offsetVal)
{
    return new Waypoint({ 
        element: triggerElement,
        handler: function(direction) {
            if (direction === 'down') {
                animatedElement.addClass(className);
                this.destroy();
            }
        },
        offset: offsetVal
    });
}

Upvotes: 1

Related Questions