LoginSignup
8
10

More than 5 years have passed since last update.

jQueryでウインドウを指定の割合までスクロールした時にコードを一度だけ実行する方法

Posted at

ウインドウを指定の割合までスクロールした時にコードを一度だけ実行する方法

Google Adwordsなどで広告を出すときにページの6割を読んだら成果にしたいという要望が有り作りました。
一度だけしか実行しないというスクリプトは、今まであまり使ってこなかったので自分用のメモとして残しておきます。

$(function(){
    var h = $(window).height();
    $(window).on('scroll', function(e){
        if ((h/$(this).scrollTop()*100) < 60) {
            // ここに実行したいコードを入れる
            $(this).off(e);
        }
    });
});
8
10
0

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
8
10