bendc / anchor-scroll

Smooth and lightweight anchor scrolling library
MIT License
363 stars 23 forks source link

Exception when there is no "a.scroll" element #21

Closed dcorb closed 8 years ago

dcorb commented 8 years ago

In pages where there is no anchors: Uncaught TypeError: Cannot read property 'addEventListener' of null In Chrome I guess, it needs a if (link) or if (links) somewhere https://github.com/bendc/anchor-scroll/blob/master/scroll.js#L57

dcorb commented 8 years ago

Fixed in the meanwhile like this:

const elements = document.querySelectorAll("a.scroll")
if (elements.length) {
  attachHandler(elements);
}
bendc commented 8 years ago

Fixed, thanks!

dcorb commented 8 years ago

That was fast! 👍