9

1ページ サイトでJQuery scrollTo プラグインを使用して、さまざまなセクション間を垂直方向にスクロールしています。

スクロールは iOS Safari を除くすべてのブラウザでうまく機能しますが、 iOS Safari はスクロールしますが、非常にぎくしゃくしています。ページで他の多くの Jquery プラグインを使用しているため、これらのいずれかと競合する可能性があります。

iPad でスムーズに動作する scrollTo の代替手段を誰かが知っている場合、または問題への取り組みを開始する場所を提案できる場合は、助けていただければ幸いです。私はこの解決策を試しましたが、成功しませんでした。

4

2 に答える 2

14

これを試してみてください

$.scrollTo(SELECTOR, 800, {
    'axis':'y'
});
于 2013-10-01T13:09:07.770 に答える
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");
   }                   
});
于 2012-06-28T17:53:15.173 に答える