jQuery scroll on Mobile Safari
I'm developing and website and I need it to scroll to an anchor. It needs to be animated, so I decided to use jQuery for that. I tried this:
function goToByScroll(id){
$('html,body').animate({scroll开发者_如何学运维Top: $("#"+id).offset().top},'slow');
}
It works perfectly on the desktop. On Mobile Safari it first goes to the top of the page, then it scrolls to the anchor I want it to scroll to. What's the trick to make it work on Mobile Safari?
What about
var top = $("#"+id).offset().top; //anchor top offset from doc top
$(window).scrollTop(top);
精彩评论