1

対応するリンクがクリックされたときにページを目的の div に自動スクロールする jquery animate() に問題があります。FF と Safari では完全に機能しますが、クロムでは、クリックするとビューが div にジャンプして元の位置に戻り、必要に応じて関連する div にスクロールします。他のブラウザーが影響を受けていない場合、jquery がジャンプしている投稿を見たことがありますが、特に chrome ではそうではありません。

JSはこちら

function initialize_autoscroll(){
  //Auto Scrolling Based on clicked links
  $('#home_button').click(function(){
     $('html, body').animate({scrollTop: 0}, 700);
     });

  $('#features_button').click(function(){
     $('html, body').animate({  scrollTop: $("#features").offset().top -50}, 700);
  });

  $('#examples_button').click(function(){
    $('html, body').animate({   scrollTop: $("#examples").offset().top -50}, 700);
  });

  $('#pricing_button').click(function(){
     $('html, body').animate({  scrollTop: $("#pricing").offset().top -50}, 700);
  });

  }

$(document).ready(function(){
  initialize_autoscroll();
});

スクロール機能を起動するタグのサンプルを次に示します。

<a id="features_button" href="#features"><i class="icon-plus"></i> Features</a>

リンク先のサンプル div を次に示します。

<div id="features" class="container-narrow" style="padding-bottom:50px">
</div
4

1 に答える 1

1

#anchorsを使用して、すべてのバインディングでデフォルト アクションを停止する必要がありますEvent.preventDefault()。例えば、

$('#home_button').click(function(evt){
  evt.preventDefault();
  $('html, body').animate({scrollTop: 0}, 700);
});
于 2012-12-27T16:11:19.750 に答える