Simple command jQuery.scrollTo({ top:0 }) fails
AleCaste opened this issue · 2 comments
When running the following command: jQuery.scrollTo({ top:0 })
You get the error:
Uncaught TypeError: Cannot read property 'slice' of undefined
at String.<anonymous> (jquery.scrollTo.js:123)
at Function.each (jquery-3.1.1.min.js:2)
at jquery.scrollTo.js:98
at Function.each (jquery-3.1.1.min.js:2)
at r.fn.init.each (jquery-3.1.1.min.js:2)
at r.fn.init.$.fn.scrollTo (jquery.scrollTo.js:64)
at Function.$.scrollTo (jquery.scrollTo.js:26)
at <anonymous>:1:8
Obviously the same happens when using the minified version jquery.scrollTo-min.js
I guess is to do with the fact that the left property is not being passed. But this used to work in previous versions.
If you just change the line:
attr[key] = val.slice && val.slice(-1) === '%' ?
... with
attr[key] = val!=null && val.slice && val.slice(-1) === '%' ?
... then it works as expected.
Hi, it fails because you are only providing top
but asking it to scroll on both axes (axis: 'xy'
) since it's the default. The plugin could handle this case silently and only scroll what it can, but I consider axis
to be the option designed for this choice.
So if you indeed only want to scroll vertically, you should rather
jQuery.scrollTo(0, { axis: 'y' })
Ahhhhh ok! Thanks for the clarification.