-1

ユーザーが特定のドキュメントの高さに達したときにポップアップを表示したい。たとえば、読者が投稿の終わりに近づくと、ポップアップがトリガーされ、入力を求めることができます (投稿が好きかどうかのコメント)。

function doch() {
    var currentscrollpos;
    if (currentscrollpos > 1500) { 
        //trigger popup
        alert(currentscrollpos);
    }
    setInterval(function() {
        currentscrollpos = $(document).scrollTop();
        return currentscrollpos;
    }, 3e3);
}​

in html 関数は doch(); を介して簡単にトリガーできます。

問題は、currentscrollpos の値をsetInterval 関数からif ループに渡すことができないことです。

4

1 に答える 1

0

ユーザーがページを下にスクロールしたときにバインドできるのに、なぜ setInterval を使用するのでしょうか?

$(window).scroll(function(){ //when a user scrolls
    if(this.pageYOffset + $(this).height() > $(document).height() - 200){ //if the scroll is within 200 px of the bottom of the page
        $('div').css('background', 'red'); //do popup
    }
});

http://jsfiddle.net/rUbwq/2/

于 2012-10-03T15:27:03.360 に答える