Help us understand the problem. What is going on with this article?

利用規約を全て読んだ上でチェックをしたら、ボタンをクリックさせる

したいこと

よくサービスにある利用規約。
こちらを以下の条件を満たさないとボタンをクリックさせないようにしたい。

(条件)
・利用規約を全て読むこと(規約を読んだ分のスクロール量を取得)
・同意するのチェックボタンの押下していること

今後よく使いそうなのでメモ。

チェック前のイメージ

スクリーンショット 2020-01-14 16.59.46.png

チェック後のイメージ

スクリーンショット 2020-01-14 16.59.58.png

ソースコード

<div id="agreeContents" class="p-agree-block">
  本文本文本文本文本文本文本文本文本文本文本文本文
    本文本文本文本文本文本文本文本文本文本文本文本文...
  <div id="agreeEnd"></div>
</div>
<div class="text-center">
<div class="m-t-35 m-b-15">
  <div class="agree-check">
    <div class="border-checkbox-section">
<div class="border-checkbox-group border-checkbox-group-primary">
  <input class="border-checkbox" type="checkbox" id="checkbox1">
  <label class="border-checkbox-label" for="checkbox1">利用規約に同意する</label>
</div>
</div>
</div>
</div>
<div class="col-md-8 offset-md-2">
  <button class="btn btn-disabled btn-block" disabled="disabled" id="agreeButton" onclick="location.href='finance-matterLists.html'">
    利用を開始する
  </button>
</div>
</div>
"use strict";

$(function(){
  let scrollHeight,scrollPosition;
  const $Contents = $("#agreeContents");
  const $Button = $("#agreeButton");
  const $checkbox = $("#checkbox1");
  let checkboxFlag;
  let scrollFlag;
  let judge = () => {
    if(checkboxFlag && scrollFlag) {
      $Button.removeAttr("disabled");
      $Button.removeClass("btn-disabled");
      $Button.addClass("btn-primary");
    }else{
      $Button.attr("disabled");
      $Button.addClass("btn-disabled");
      $Button.removeClass("btn-primary");
    }
  }
  $Contents.scroll(function() {
    scrollHeight = $(this).get(0).scrollHeight;
    scrollPosition = $Contents.get(0).offsetHeight + $(this).scrollTop();
    if (scrollHeight <= scrollPosition ) {
      scrollFlag = true;
    }
    judge();
  });
  $checkbox.click(function() {
    checkboxFlag = $checkbox.get(0).checked;
    judge();
  });
});

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away