您好我正在编写自定义航点功能,我收到错误,并想知道是否有人可以帮助我。该函数使用的是waypoints.js
http://imakewebthings.com/waypoints/
这是我到目前为止的代码
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);
我在第三行收到错误
handler: function(direction) {
"未捕获的SyntaxError:意外的令牌("
谢谢!
答案 0 :(得分:1)
您需要使用逗号分隔函数参数,而不是分号。您还将选定的jQuery对象作为triggerElement传递,因此您不需要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
});
}