开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜