ウィンドウ最上部のスクロール位置の取得
function getScrollTop(){
$("#result").text($(window).scrollTop() + 'px');
}
$(window).on("load scroll", getScrollTop);
サンプル
ウィンドウ最下部のスクロール位置の取得
function getScrollTop(){
$("#result").text($(window).scrollTop() + $(window).height() + 'px');
}
$(window).on("load scroll resize", getScrollTop);
サンプル
ウィンドウ最下部のスクロール位置がある要素まで到達したらイベントを発生させる
var scrollBottom;
var lastTop = $("#last").offset().top;
function getScrollTop(){
scrollBottom = $(window).scrollTop() + $(window).height();
$("#result").text(scrollBottom + 'px');
if(scrollBottom >= lastTop){
$("#result").text('lastまでスクロールされました');
}
else{
$("#result").text(scrollBottom + 'px');
}
}
$(window).on("load scroll resize", getScrollTop);
サンプル