アップデート:
これは、問題を示すjsbin の例です。
更新 2: fudgeyのおかげで修正されたバージョン
がここにあります。
基本的に、ウィンドウをページ上のアンカーにスクロールする次のjavascriptがあります。
// get anchors with href's that start with "#"
$("a[href^=#]").live("click", function(){
var target = $($(this).attr("href"));
// if the target exists: scroll to it...
if(target[0]){
// If the page isn't long enough to scroll to the target's position
// we want to scroll as much as we can. This part prevents a sudden
// stop when window.scrollTop reaches its maximum.
var y = Math.min(target.offset().top, $(document).height() - $(window).height());
// also, don't try to scroll to a negative value...
y=Math.max(y,0);
// OK, you can scroll now...
$("html,body").stop().animate({ "scrollTop": y }, 1000);
}
return false;
});
それは完全に機能します...手動でウィンドウをスクロールしようとするまで。スクロールバーまたはマウスホイールがスクロールされると、現在のスクロールアニメーションを停止する必要があります...しかし、これを行う方法がわかりません。
これが私の原点なのかもしれません…
$(window).scroll(e){
if(IsManuallyScrolled(e)){
$("html,body").stop();
}
}
IsManuallyScrolled
...しかし、関数のコーディング方法がわかりません。e
Google Chrome のコンソールで(オブジェクト)をチェックアウトしましたが、私event
の知る限り、手動スクロールと jQuery のスクロールを区別する方法はありませんanimate()
。
手動スクロールと jQuery の$.fn.animate
関数を介して呼び出されたスクロールを区別するにはどうすればよいですか?