2017-06-13 58 views
3

我想基於滾動通知事件。我發現Waypoints可以解決我的問題,但我收到的所有示例jQueryReactjs。我如何在CoffeeScript中使用它?

我正在使用下面的代碼。它每次都被解僱,但我希望它只在達到waypoint-header時纔會被解僱。我有這div在重複模式下,我的意思是這個div可用後的一些列表項(列表中的每20項後)。請幫我解決這個問題。WayScript與CoffeeScript

$(window).scroll -> 
     waypoint = new Waypoint(
      element: document.getElementById('waypoint-header'), 
      handler:(direction) -> 
       console.debug 'hello' 
     ) 

回答

0

這裏是CoffeeScript中沒有jQuery的一個例子,陣營:

waypoint = new Waypoint 
    element: document.getElementById('waypoint-header'), 
    handler: (direction) -> 
     console.log 'hello' 

你並不需要添加一個事件監聽器,航點庫做它本身。

working codepen

+0

它被基於滾動發射了很多次。只有當它到達'div' id路點標題時,我纔會激發'Waypoint'。 –

+0

@JeetenParmar,我看到了,請看看我更新的答案。 –

+0

它給錯誤'錯誤:沒有元素選項傳遞給Waypoint構造函數' –

0

如果我得到它的權利,這是正常的電流代碼在任何滾動事件被解僱。 如果你只需要觸發一次當達到waypoint-header我想,你應該創建一個航點沒有任何滾動事件指示here

waypoint = new Waypoint 
     element: document.getElementById('waypoint-header'), 
     handler:(direction) -> 
      console.debug 'hello' 

要通知的內部列表中的每個元素,我建議更改標識的上課,嘗試這個。

waypoint = $(".waypoint-header").waypoint -> 
     element: document.getElementById('waypoint-header'), 
     handler:(direction) -> 
      console.debug 'hello' 
+0

這是錯誤'錯誤:沒有元素選項傳遞給Waypoint構造函數' –

+0

還有一件事,我有'

waypoint-header
'在列表中的許多地方。我的意思是每20個項目之後。 –

+0

所以然後元素選項應該與其他我在查看投訴的時候區分開來,你不應該使用像'class'這樣的'id'標籤,'id'通常意味着在文檔中是唯一的。 – ibubi