문제

This question is only applicable for mobile Safari.

On my site I have reviews, and I have review stars at the top of my product. When the user taps the review stars I want the screen to scroll down to the reviews of the product. On Android and Desktop the page scrolls as excepted, but on iOS all it does is flicker and stay in the same location.

Here is the code:

$('html, body').animate({
    scrollTop: $("#reviews").offset().top,
    scrollLeft: 0
}, 400);

Here is a jsbin demonstrating the problem.

http://jsbin.com/losuz/3/

Thanks

도움이 되었습니까?

해결책

I did find the correct answer to my issue, the scrollLeft was causing issues in iOS.

$('html, body').animate({
    scrollTop: $("#reviews").offset().top
}, 400);

This can be tested in http://jsbin.com/losuz/6/.

For comparison you can see the functionality suggested in Oscar Paz's answer here: http://jsbin.com/losuz/5/

I prefer the animation for the smoothness of the slide, but Oscar's answer is also valid.

다른 팁

Have you tried scrollIntoView?

$('#reviews')[0].scrollIntoView();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top