waypoints
waypoints copied to clipboard
"Uncaught TypeError: Cannot read property 'top' of undefined"
I'm getting "Uncaught TypeError: Cannot read property 'top' of undefined" error on jquery.waypoints.min.js line 7. Everything is working ok, besides the error in console. Here is the following code I have.
var mainNav = $('.navigation');
var $section = $('section'),
white = $("section[data-color='white']"),
black = $("section[data-color='black']");
var waypoint = new Waypoint({
element: white,
handler: function (direction) {
mainNav.removeClass('light');
if (direction == 'up') {
mainNav.addClass('light');
}
}
});
var waypoint = new Waypoint({
element: black,
handler: function (direction) {
mainNav.addClass('light');
if (direction == 'up') {
mainNav.removeClass('light');
}
}
});
@emilium In your example white and black are jQuery objects, not HTMLElements. The element option in Waypoints expects a plain ol' element. You could get around this by using the jQuery extension the library provides:
white.waypoint({
handler: function(direction) {
...
}
});
// same for black
@imakewebthings Oh. Great thanks. It's working perfectly now without any errors.