LoginSignup
1

More than 5 years have passed since last update.

スクロールが終わった時にイベント処理

Posted at
sample.js
// スクロールイベントを設定
window.addEventListener( "scroll", function(){
    // setTimeoutIdの内容がある場合は、setTimeoutをキャンセル
    if(setTimeoutId){
        clearTimeout(setTimeoutId) ;
    }

    // 新しくsetTimeoutイベントを設定
    setTimeoutId = setTimeout( function(){
        // スクロール終了時の処理内容
        if("<%=rirekiKeepFlg %>" == "1"){
            // スクロール位置保管
            ajaxSaveScroll();
        }

        // setTimeoutIdを空にする
        setTimeoutId = null;
    }, 500) ;
});

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1