waypoints icon indicating copy to clipboard operation
waypoints copied to clipboard

"Uncaught TypeError: Cannot read property 'top' of undefined"

Open emilium opened this issue 11 years ago • 2 comments

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 avatar Apr 24 '15 04:04 emilium

@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 avatar Apr 24 '15 04:04 imakewebthings

@imakewebthings Oh. Great thanks. It's working perfectly now without any errors.

emilium avatar Apr 24 '15 05:04 emilium