ウィンドウ.scrollTop(整数を返します)を見てみましょう。
$(window).scroll(function() {
if ($(this).scrollTop() === 100) { // this refers to window
alert("You've scrolled 100 pixels.");
}
});
が、あなたはそれが警告ボックスをトリガー習慣102pxスクロールしている場合。
あなたはちょうどそれがtriggedされている場合は、一度にtrueに設定し、グローバル変数を持つアラートをトリガーする場合:
$(function(){
var hasBeenTrigged = false;
$(window).scroll(function() {
if ($(this).scrollTop() >= 100 && !hasBeenTrigged) { // if scroll is greater/equal then 100 and hasBeenTrigged is set to false.
alert("You've scrolled 100 pixels.");
hasBeenTrigged = true;
}
});
});
か、単に警告ボックスがtriggedされた後、スクロールイベントをバインド解除:
を
$(function(){
$(window).bind("scroll.alert", function() {
var $this = $(this);
if ($this.scrollTop() >= 100) {
alert("You've scrolled 100 pixels.");
$this.unbind("scroll.alert");
}
});
});
みては? –