2016-10-26 3 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">