kswedberg / jquery-smooth-scroll

Automatically make same-page links scroll smoothly
MIT License
1.97k stars 427 forks source link

scroll broken with latest browser upgrades #108

Closed david-pm closed 4 years ago

david-pm commented 7 years ago

I hope this might come in handy for someone, or might be something worth mentioning in the README. This library stopped working for me overnight.

Dug around and found this issue: https://github.com/simov/simplr-smoothscroll/issues/27

which turned me onto the changes regarding document.scrollingElement

I was previously doing something like:

$.smoothScroll({
      scrollElement: $('body'),
      offset: 200,
      speed: 750,
      scrollTarget: '#' + this.attributes["data-smooth"].value
});

Taking document.scrollingElement into consideration the fix for me was essentially to just use it like this:

$.smoothScroll({
      scrollElement: $(document.scrollingElement),
      speed: 750,
      scrollTarget: '#' + this.attributes["data-smooth"].value
});
kswedberg commented 7 years ago

Thanks a lot for bringing this to my attention. I remember reading about scrollingElement a while back but it kind of fell off my radar.

This plugin also includes a firstScrollable() method that you can use like $('html, body').firstScrollable(). So, it would use the "html" selector, which is effectively the same as document.documentElement. The plugin uses that by default, so if you omit the scrollElement option in your code, it should work. In any case, I think I'll use document.scrollingElement if it's available for the firstScrollable() method. And I like your idea of including a warning in the README. So, thanks again for the heads up.

kswedberg commented 7 years ago

Oh ha, I guess I added document.scrollingElement detection about a year and a half ago: https://github.com/kswedberg/jquery-smooth-scroll/blob/f040c54c4ecc8372326577a49b83d52fa3a9ac3b/src/jquery.smooth-scroll.js#L62-L65

But, yeah, will still add something to the readme.