2013-07-18 37 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(); 

});