2013-07-18 35 views
0

我使用航点(http://imakewebthings.com/jquery-waypoints/#shortcuts-examples)和绿色环(http://www.greensock.com/)来触发某些元素在用户处于不同级别的页面页面时的移动。如何实现回调函数或处理程序选项

$(".three").waypoint(mover($(".four"), 1, 32, 32)); 

然而,JavaScript控制台不断给我这个消息(尽管一切工作完美,视觉)

Uncaught Error: jQuery Waypoints needs a callback function or handler option. jquery.js:4 
x.extend.error jquery.js:4 
$.fn.(anonymous function) waypoints.js:360 
(anonymous function) scroll.js:15 
c jquery.js:4 
p.fireWith jquery.js:4 
x.extend.ready jquery.js:4 
q 

我试图返回“真:

function mover(speed, targetx, targety) { 
    TweenMax.to($(".four"), speed, {x:targetx, y:targety}); 
    console.log("waypoint reached"); 
    alert("Down") 
} 

被称为“但错误不会消失。我如何将回调函数或处理程序选项集成到我的函数中?

回答

0

如果您invoke it without a callback or parameter Waypoint出现错误。当你向上或向下滚动一个元素时,完成生活的目的就是做一些事情。

如果你的代码正在做你需要它做的事情,也许你根本不需要航点。

你可以发布竞争的代码,或至少一个完整的示例呼叫到路点吗?

0

正如mostly_perl_guy说,你需要,当你调用waypoint()定义一个回调函数:

http://jsfiddle.net/FPzUy/1/

$(function() { 

      // this works 
    $('#w').waypoint(function() { 
     console.log('hello'); 
    }); 

      // this fails 
    $('#w2').waypoint(); 

});