-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smooth scroll into view not working in >= Chrome 52 #28
Comments
Can you specified better what's the behavior or error in console you see? Just tested in Chrome 53 and it works just fine in the demo page. Also, remember the current version of Chrome is 51 so higher version could still have bugs. |
There are no console errors. |
I'm on Chrome 53.0.2765.0 canary (64-bit) OSX and works perfect on both examples from the demopage. Please remember that those are dev build versions from Chrome so it's normal to find bugs on their side. Current version of Chrome is 51 right now http://googlechromereleases.blogspot.com.ar/2016/06/stable-channel-update_6.html and is where the polyfill should work well. |
I'm also experiencing this behavior in Chrome (Version 53.0.2785.143 (64-bit)) on OSX - both on the demo page and in a project I'm working on. :( Looks like the test whether to polyfill or not bails because Chrome already supports it: https://github.com/iamdustan/smoothscroll/blob/master/src/smoothscroll.js#L14 This is the pain of polyfilling experimental features I guess... |
@rasmusfl0e I'm on the same Chrome version and OS and the demo page works. |
I dont see this working too in Chrome 58.0.3029.110 (64-bit). It just jumps to the element position but smooth does not work.
|
This is an issue in Chrome itself. |
Does not work in Chrome 60.0.3112.101 (Official Build) (64-bit) either. While it is an issue in Chrome, shouldn't this polyfill take care of it until the new Chrome version is released? |
in Chrome 61 (Version 61.0.3163.100 (Official Build) (64-bit)) scrollIntoView({ behavior: 'smooth' }) scrolls to middle of element, not to the top. Without behavior smooth (with auto) it works fine. |
@fwitkowski that's actually the native implementation of the spec from Chrome. You can force the polyfill to override the native implementation if you want it to work in the same way as Firefox. |
Thanks Jeremenichelli, how can I overwrite this behavior? |
@jeremenichelli , I tried your suggestion and sitll - different behavior in chrome and firefox. Even in that demo page (http://iamdustan.com/smoothscroll/), if you try clicking SCROLL INTO VIEW in chrome and firefox, you'll see the difference. |
The demo page is not forcing the polyfill implementation, so it's gonna behave differently. If you could provide an isolated case where the forcing implementation feature doesn't work it would help us analyze what's happening. |
Check this example in jsfiddle: https://jsfiddle.net/fwitkowski/jp5Lc6sv/1/ Compare behavior in chrome and firefox. |
This is not an issue on the library, as the README states the global flag needs to be set to From the README:
Also, jsfiddle doesn't let you override |
If really wanna see that this works, the best way is to download the repo, and add the flag on the |
It does not work on Version 63.0.3239.132 (Official Build) (64-bit) macOS as of this writing. An easy way to test is to run this in your console and see if it scrolls the page to the top:
If you omit the options it works again (non-smoothly):
|
@thinkloop and everyone here, there are some inconsistencies between Chrome and Firefox implementations. The polyfill can't selectively override methods, it just runs or not. Right now, running That said, the scripts throws an error when called the method with those arguments so it's definitely a bug that we will take care of. In the mean time if you want to scroll to top you can run: window.scroll({ top: 0, behavior: 'smooth' }) This will work in all browsers consistently. Thanks everyone for reporting ❤️ |
Thanks for the workaround, that helps my specific case.
If you use an unsupported value and not "smooth" it displays an error message. It seems like at minimum specifying "smooth" should scroll to the top, whether smoothly or not, next option is showing an error, doing nothing seems like the least optimal behavior. |
Sorry @thinkloop I didn't expressed myself well, or used the wrong words. What I meant was that when scrolling into view the body element both browsers do different stuff, probably because the spec doesn't specify any behavior at all around that case. |
This is interesting, I did a few other tests and it seems that if an element consumes the whole viewport or more, it does not scroll, while if any part of the viewport is not consumed, it will scroll to the top of the element - try this from the very bottom of this github page, then from mid-way down the page:
To be clear there is still a bug here: that 'smooth' does not work consistently to non-smooth. Whatever logic is decided upon, the smooth option should do exactly as the non-smooth option, just with smoothness or not. Right now they behave differently. If you try the above code without the smooth, u will see it will always scroll to top. |
Totally. I think I've never tried the polyfill with an element occupying more space than the viewport, I will take this as part of the fix and see what I find. Thanks for the suggestions and insights. |
Using |
@dietergeerts what is |
'group' is one html element. I'll see if I can create a live case to test. The code is on a work project. |
Disclaimer: I'm not using iamdustan's smooth scroll polyfill, but I ran into this same problem with vanilla javascript in Chrome, and found this Issue (and not much else) in my search for a solution. This fix seems to be working consistently for me. My fix was to use
I am using Chrome 68.0.3440.106 on macOS. My fix (under my circumstances at least) works in Firefox 61.0.2 as well. Hopefully this helps someone. |
I found that passing top.scrollIntoView({ behavior: 'smooth' }); The above doesn't work, while the code below does. top.scrollIntoView({
behavior: 'smooth',
block: 'start',
inline: 'nearest'
}); |
@Laurensdc Thanks. Your suggestion worked for me. |
Is there any way to make the smooth transition from scrollIntoView quite faster, right now it works fine but if there is any possibility to speed up the smooth transition, it will be very helpful. Thanks in Advance |
I guess it's not possible with current implementation. |
chrome version 78.0.3904.70(正式版本) (64 位) |
document.querySelector('.className).scrollIntoView({behavior: "smooth"}); -> not working Similarly for the Viewchild reference this.scroll.nativeElement.scrollIntoView({block: 'end', behavior: "smooth"})-> not working |
document.querySelector(target).scrollIntoView(); Tried both the ways in chrome Version 81.0.4044.138(official-build). but no luck, smooth scroll is not working |
Try putting it inside a setTimeout, it worked for me in that way. |
foo.scrollIntoView({ behavior: 'smooth', block: 'center' }); ----> old setTimeout(() => foo.scrollIntoView({ behavior: 'smooth', block: 'center' }), 0); -----> new |
@MadaShindeInai are scrolling on events? |
Providing a solution that worked for me with the caveat that it requires jQuery so could be ported to vanillaJS:
|
After 4 years, this still doesn't seem to work... This works every single time, without a timeout, called with react-animate-height onAnimationEnd:
This doesn't scroll as expected. It seems to even scroll in the opposite direction:
I've also tried using CSS scroll-behavior: smooth, which has the same problems as the above method. |
Changing behavior to behaviour worked for me in Chrome. |
@leocavalcante , but then we are dependant on the user to have this setting on as developers, which really is not good. |
@dietergeerts if the user don't want to see it animated/smooth, why you should force it to be? ¯_(ツ)_/¯ |
@leocavalcante , because it can contribute to a better UX, and if we would use it, and the user has the option turned off, then the site or app will look badly done. |
If you are using Angular and want to add smooth "scroll into view" functionality to your project which works on any browser and doesn't depend on Windows visual effects configuration, I would recommend ngx-smooth-scroll. |
It didn't work for me on "document.ready" but ok on other event. setTimeout(function () { |
I still have the same problem. Was it resolved? |
@jmengere see this comment: #28 (comment) |
Still have this problem, #28 (comment) - doesn't work for me |
Yeah still facing ScrollIntoView() problem, how to fix it, I am unable to implement in basic Vanilla Js also. |
The smooth scroll behaviour doesn't take affect for
scrollIntoView
in chrome 52 for some reason.The behaviour is fine for
scrollBy
and other functions though.Tested on http://iamdustan.com/smoothscroll/
The text was updated successfully, but these errors were encountered: