2017-06-14 74 views
0

你好我正在写一个自定义的航点功能,我得到一个错误,并想知道如果有人可以帮我。该功能是使用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:意外的令牌(“

谢谢!

回答

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 
    }); 
} 
+0

真棒谢谢你,我会尝试了这一点,如果它的工作原理生病接受的答案 –

+1

是基本要点它。你可以避开包装“waypoint”函数,只需在脚本中直接调用新的Waypoint({...直接在代码中,如果你有参数可用。 – mjw