JQuery scrollTo插件在iOS上变成了Jerky

nfr*_*t21 9 jquery flicker scrollto ios

我在我们的单页网站上使用JQuery scrollTo插件在不同部分之间垂直滚动.

滚动在所有浏览器中运行良好,除了 iOS Safari,滚动但非常生涩.我在页面上使用了许多其他Jquery插件,因此可能与其中一个插件冲突.

如果有人知道scrollTo的替代方案可以在iPad上顺利运行,或者可以建议从哪里开始解决问题,我会很感激帮助.我试过这个解决方案,但没有成功.

Mo.*_*Mo. 14

试试这个吧

$.scrollTo(SELECTOR, 800, {
    'axis':'y'
});
Run Code Online (Sandbox Code Playgroud)


nfr*_*t21 1

感谢阿纳尔的提示。

你的建议让我走上了正确的道路,在这个 JSFiddle的帮助下,我现在有了我想要实现的平滑滚动,平滑的动画滚动到每个部分并自动突出显示活动菜单项。

// Cache selectors
var lastId,
    topMenu = $("#top-menu"),
    topMenuHeight = topMenu.outerHeight()+15,
    // All list items
    menuItems = topMenu.find("a"),
    // Anchors corresponding to menu items
    scrollItems = menuItems.map(function(){
      var item = $($(this).attr("href"));
      if (item.length) { return item; }
    });

// Bind click handler to menu items
// so we can get a fancy scroll animation
menuItems.click(function(e){
  var href = $(this).attr("href"),
      offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1;
  $('html, body').stop().animate({ 
      scrollTop: offsetTop
  }, 300);
  e.preventDefault();
});

// Bind to scroll
$(window).scroll(function(){
   // Get container scroll position
   var fromTop = $(this).scrollTop()+topMenuHeight;

   // Get id of current scroll item
   var cur = scrollItems.map(function(){
     if ($(this).offset().top < fromTop)
       return this;
   });
   // Get the id of the current element
   cur = cur[cur.length-1];
   var id = cur && cur.length ? cur[0].id : "";

   if (lastId !== id) {
       lastId = id;
       // Set/remove active class
       menuItems
         .parent().removeClass("active")
         .end().filter("[href=#"+id+"]").parent().addClass("active");
   }                   
});
Run Code Online (Sandbox Code Playgroud)