2016-10-26 18 views
3

私のレールプロジェクトでウェイポイントを使用しています。 (gem waypoints_railsを使用)ウェイポイント - ウェイポイントコンストラクタに渡される要素オプションがありません

Waypointsはうまく機能しているページでうまくいきます。私がウェイポイントを使用している要素は、このページにのみ存在します。私はWaypoint Inviewを使用しています。

var inview = new Waypoint.Inview({ 
    element: $('#the-element')[0], 
    entered: function(direction) { 
    console.log("working");   
    } 
}); 

これは正しく動作しています。

しかし、私のホームページは今、このエラーを与えている:

Uncaught Error: No element option passed to Waypoint constructor 

任意のヘルプ?

答えて

3

私は同じ問題を抱えていました。条件にウェイポイントをラップして、その要素がページに存在するかどうかを確認してください。

if ($("#the-element").length) { 
    var inview = new Waypoint.Inview({ 
     element: $('#the-element')[0], 
     entered: function(direction) { 
      console.log("working");   
     } 
    }); 

} 
0

このメッセージは、通常、JqueryがHTML要素を検出しないことを示します。

var waypoint = new Waypoint({ 
element: document.getElementsByClassName('element-features'), 
handler: function(direction) { 
    if (direction == "down") { 
    $('nav').addClass('sticky'); 
    } else { 
    $('nav').removeClass('sticky'); 
    } 
}, 
offset: '60px' 
}); 

あなたはHTML要素(クラスまたはID)で使用される定義に応じてのgetElementsByClassNameまたはgetElementsByIDを使用する:この実施例(jqueryの3.2.1/4.0.1ウェイポイント)を確認してください。

<section class="element-features"> 
関連する問題