I have written a javascript smooth scrolling function to provide navgation on a one-pager. The code is basically like the one at the bottom.
The function is called with the number of pixels to scroll by, which is then divided into 30 steps and then scrolled in a loop until the number is achieved. Thereby I tried both looping variants with setTimeout and requestAnimationFrame.
It works almost perfectly in all desktop browsers as well as my android phone, however Safari and Chrome on IOS devices could not get to the desired point. Testing with alert in each iteration showed, that all values are calculated correctly, however, the actual scrolled amount does not match, resulting in the scrolling stop in the wrong position.
I cannot provide a demo since it is a commercial application in development, also I tried a make a simplified jsfiddle, but this does not actually show the error, so it must be the combination with something else that causes the issue (probably css fixed position, min-height 100vh, scroll event handlers...?).
I definitely think this strange behaviour and should have been noticed by others before. Can anybody provide me with a hint what to do?
function scrollstep(dist) {
var n = Math.floor(dist / 30 * (1 - Math.abs(scrstp_dist / dist - 0.5)));
if (Math.abs(scrstp_dist + n) < Math.abs(dist)) {
scrstp_dist+= n;
// alert(n);
w.scrollBy(0, n);
w.requestAnimationFrame( function(timestamp) { scrollstep(dist); } );
} else {
w.scrollBy(0, dist - scrstp_dist);
}
}