0

タイトルはそれ自体を物語っています。では、jQueryまたはjavascriptを使用してそれを行うにはどうすればよいですか?スクロールバーがウィンドウの最後に到達したかどうかはわかりますが、次のようになります。

$(window).scroll(function(){
   if  ($(window).scrollTop() == $(document).height() - $(window).height()){
alert('you have reached the bottom');
}
});

では、特定のセクションに到達したかどうかをどのように判断して、アラートを出すのでしょうか。ありがとう。

4

2 に答える 2

3

解決するのは難しい問題ではありませんが、jQueryWaypoints ...要件を満たすための非常に優れたプラグインを確認してください。

彼らのサイトからの簡単な例:

$('.entry').waypoint(function() {
   alert('You have scrolled to an entry.');
});

エレガントで読みやすく、プラグインは4kb未満と非常に小さいです。

于 2012-06-15T12:07:54.670 に答える
0

プラグインなしでこれを行う方法はこれです。

// calculate where the bottom of the post is positioned
var postBottom = $(".post").offset().top + $(".post").height();

$(window).scroll(function(){
    // check if the bottom of the post is smaller than the window height
    if (postBottom < $(window).height()){
        alert('you have reached the bottom of the post');
    }
});
于 2012-06-15T12:14:30.017 に答える