Hello I have created a custom waypoint function which works well but I would like the ability to be able to add a function to it.
Here is the working custom waypoint function:
function createWaypoint (triggerElementId, animatedElement, className, offsetVal) {
var waypoint = new Waypoint({
element: document.getElementById(triggerElementId),
handler: function(direction) {
if (direction === 'down') {
jQuery(animatedElement).addClass(className);
this.destroy();
}
},
offset: offsetVal
});
}
//Waypoint Instances
createWaypoint("x", ".y", "z", 500);
Next I would like the add the ability to add a function to the if statement and here is what I came up with:
function createWaypoint (triggerElementId, animatedElement, className, offsetVal, functionName) {
var waypoint = new Waypoint({
element: document.getElementById(triggerElementId),
handler: function(direction) {
if (direction === 'down') {
jQuery(animatedElement).addClass(className);
functionName();
this.destroy();
}
},
offset: offsetVal
});
}
function test() {
alert('Hello World');
}
//Waypoint Instances
createWaypoint("x", ".y", "z", 500);
createWaypoint("x", null, null, null, test);
I added the functionName on line 1 and 7. Then I tried to call it on the very last line. The function "test" does not trigger and I get the error:
Uncaught TypeError: functionName is not a function.
Can anyone help out with this?
Thanks!