ScrollTop到所需的位置不适用于iPad

时间:2017-09-19 05:52:32

标签: php jquery

我有以下代码来滚动 attr

所定位的所需部分
$('html, body').animate({
  scrollTop: $( attr).offset().top -300
}, 500)

页面成功滚动到桌面上的那个位置,但不是在iPad中。我必须将 300 的值更新为iPad的合适值。如何使其动态化以便在所有设备中正常工作?

2 个答案:

答案 0 :(得分:0)

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

尝试此操作...添加目标ID或类。

答案 1 :(得分:0)

请参考

http://jsfiddle.net/lollero/ZVdRt/

jQuery jump or scroll to certain position, div or target on the page from button onclick

例如。

$("body, html").animate({ 
    scrollTop: $( $(this).attr('href') ).offset().top 
}, 600)
相关问题