1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ページの最下部に行ったらコンテンツが追加されるような処理を実装してみた

Posted at

こんな感じの挙動です
Imgur

まずスクロール値を監視

data : function(){
  return{
    scrollY : 0 //スクロール値が保存される
  }
},
mouted : function(){
  window.addEventListener('scroll',this.handleScroll);
},
methods : {
  handleScroll : function(){
    this.scrollY = window.scrollY;
  }
}

スクロールを監視して最下部に来た時に処理を実行

watch : {
  scrollY : function(){
    let bottom = document.body.scrollHeight - document.body.clientHeight;
    if(bottom <= this.scrollY){
      //最下部に来たときに実行される
      this.getNextContent();
    }
  }
}
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?