Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                  <div class="wrapper">
    <div class="content">
      <form action="">
        <div class="price-info">
          <div class="total" id="total">合計<span>1商品</span>選択中</div>
          <div class="price-txt">合計金額<span class="red"><span class="price-chg" id="price-chg">6,000</span>円</span>(税込)</div>
        </div>
        <p>カートに入れる商品を選択してください</p>
        <div class="select-item">
          <ul class="item-list item-calc">
            <li>
              <input type="checkbox" class="select-checkdox" id="select-checkdox-01" name="select-checkdox">
              <label for="select-checkdox-01" class="item-info">
                <div class="check-img"></div>
                <div class="ttl">課金アイテムA</div>
                <div class="price">150円</div>
              </label>
            </li>
            <li>
              <input type="checkbox" class="select-checkdox" id="select-checkdox-02" name="select-checkdox" >
              <label for="select-checkdox-02" class="item-info">
                <div class="check-img"></div>
                <div class="ttl">課金アイテムB</div>
                <div class="price">500円</div>
              </label>
            </li>
            <li>
              <input type="checkbox" class="select-checkdox" id="select-checkdox-03" name="select-checkdox" checked>
              <label for="select-checkdox-03" class="item-info">
                <div class="check-img"></div>
                <div class="ttl">課金アイテムC</div>
                <div class="price">500円</div>
              </label>
            </li>
            <li>
              <input type="checkbox" class="select-checkdox" id="select-checkdox-04" name="select-checkdox" >
              <label for="select-checkdox-04" class="item-info">
                <div class="check-img"></div>
                <div class="ttl">課金アイテムD</div>
                <div class="price">1,000円</div>
              </label>
            </li>
          </ul>
          <h3 class="subttl">今だけ!!お得な課金パック!</h3>
          <ul class="item-list item-calc">
            <li>
              <input type="checkbox" class="select-checkdox" id="select-pack-checkdox-01" name="select-checkdox" >
              <label for="select-pack-checkdox-01" class="item-info">
                <div class="check-img"></div>
                <div class="ttl">課金パックA</div>
                <div class="price">3,000円</div>
              </label>
            </li>
            <li>
              <input type="checkbox" class="select-checkdox" id="select-pack-checkdox-02" name="select-checkdox">
              <label for="select-pack-checkdox-02" class="item-info">
                <div class="check-img"></div>
                <div class="ttl">課金パックB</div>
                <div class="price">5,000円</div>
              </label>
            </li>
            <li>
              <input type="checkbox" class="select-checkdox" id="select-pack-checkdox-03" name="select-checkdox">
              <label for="select-pack-checkdox-03" class="item-info">
                <div class="check-img"></div>
                <div class="ttl">課金パックC</div>
                <div class="price">10,000円</div>
              </label>
            </li>
          </ul>
        </div>
        <div class="btn-area"><a class="form-submit btn-submit" href="#">カートに入れる</a></div>
      </form>
    </div>
  </div>
              
            
!

CSS

              
                 input[type="checkbox"]{
   display: none;
}
html{
  font-size:62.5%;
}
body{
  font-size:1.4rem;
  line-height:1.3;
  letter-spacing:0.05em;
}
a{
  text-decoration:none;
}
ul,li{
  margin:0;
  padding:0;
  list-style-type:none;
}
div,p{
  margin:0;
  padding:0;
}
.wrapper{
  margin:0 auto;
  width:100%;
  max-width:1080px;
}
.content{
  padding:40px 0;
}
//color
.red{
  color:#f00;
}
//price-info
.price-info{
  background:#efefef;
  padding:20px;
  margin-bottom:40px;
  box-sizing:border-box;
}
.total{
  font-size:1.8rem;
  margin-bottom:10px;
  span{
    font-weight:bold;
  }
}
.price-txt{
  font-size:1.6rem;
  span{
    display:inline-block;
    margin:0 3px;
  }
}
.select-item{
  padding-top:40px;
}
//item-list
.item-list{
  display:flex;
  flex-wrap:wrap;
  >li{
    margin-left:10px;
    &:first-child{
      margin-left:0;
    }
  }
}
label{
  display:block;
  position:relative;
  padding:10px 10px 10px 40px;
  width:100%;
  height:100%;
  border:2px solid #ddd;
  border-radius:5px;
  box-sizing:border-box;
  transition: border-color .3s,color .3s
}
.check-img{
  position:absolute;
  width:12px;
  height:12px;
  border-radius:5px;
  border:2px solid #ddd;
  left:10px;
  top:0;
  bottom:0;
  margin:auto;
  &:before{
    content:"";
    position:absolute;
    width:4px;
    height:2px;
    background:#fff;
    left:2px;
    top:5px;
    transform:rotate(45deg);
    border-radius:5px 0 0 5px;
    transition:.3s;
  }
  &:after{
    content:"";
    position:absolute;
    width:6px;
    height:2px;
    background:#fff;
    left:4px;
    top:5px;
    transform:rotate(-45deg);
    border-radius:0 5px 5px 0;
    transition:.3s;
  }
}
input[type="checkbox"]:checked{
  +label{
    border-color:#33cccc;
    color:#33cccc;
    .check-img{
      &:before{
        background:#33cccc; 
      }
      &:after{
        background:#33cccc;    
      }
    }
  }
}
//subttl
.subttl{
  margin:40px 0 10px;
}
//btn
.btn-submit{
  display:block;
  width:100%;
  max-width:300px;
  padding:10px 0;
  margin:0 auto;
  border:2px solid #33cccc;
  text-align:center;
  border-radius:5px;
  color:#33cccc;
  transition:.3s;
  &:hover{
    background:#33cccc;
    color:#fff;
  }
}
.btn-area{
  margin-top:40px;
}
              
            
!

JS

              
                   (function () {
     let $total = $('#total>span');
      let $priceChg = $('#price-chg');
      let $itemCalcLi = $('.item-calc > li');
      let selectItemArray = []; //金額とcheckの有無を格納する 


      //金額と個数を計算、出力
      function priceTxtChange() {
        let price = 0; //金額
        let priceNum = 0; //個数

        for (let b = 0; b < selectItemArray.length; b++) {
          if (selectItemArray[b][1] === true) {//selectItemArray[b][1]の値がtrueのものだけを計算する
            price = price + selectItemArray[b][0];
            priceNum++;
          }
        }
        price = String(price).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,'); //カンマ区切りにする
        $priceChg.text(price);
        $total.text(priceNum + '商品');
      }

      //最初にに金額とcheckの有無を格納する
      function createItemCheckArray() {
        for (let a = 0; a < $itemCalcLi.length; a++) {
          let itemCalcLiPrice = $itemCalcLi.eq(a).find('.price').text();
          itemCalcLiPrice = itemCalcLiPrice.replace(/[^0-9]/g, ''); //数字だけ抜き出す
          itemCalcLiPrice = Number(itemCalcLiPrice); //数値に変換

          //選ばれているかどうか 選ばれているならtrue
          let itemRSelected;
          let watchCheckbox = $itemCalcLi.eq(a).find('input[type="checkbox"]');
          if (watchCheckbox.prop('checked')) {
            itemRSelected = true;
          } else {
            itemRSelected = false;
          }
          selectItemArray.push([itemCalcLiPrice, itemRSelected]);//金額とcheckの有無を格納
        };
      };
     
     //load時に読ませる
     createItemCheckArray();
     priceTxtChange();
     
     
      //クリックされた時に値を変える
      function changeItemCheckArray(index, thisCheckToggle) {
        if (thisCheckToggle) {
          // チェックボックスがチェックされているならselectItemArray[index][1]をtrueに、違うならfalseに書き換える
          selectItemArray[index][1] = true;
        } else {
          selectItemArray[index][1] = false;
        }
        return priceTxtChange();//priceTxtChangeを呼びだし計算
      };
     
     //$itemCalcLiクリックした時
      $itemCalcLi.on('click', function () {
        var index = $('.item-calc >li').index(this);
        let thisCheckToggle;
        let thisCheckbox = $(this).find('input[type="checkbox"]');

        if (thisCheckbox.prop('checked')) {//チェックボックスがチェックされているならtrue、違うならfalse
          thisCheckToggle = true;
        } else {
          thisCheckToggle = false;
        }
        return changeItemCheckArray(index, thisCheckToggle);
      });

      //ボタンを押されたらsubmit
      // let $formSubmit = $('.form-submit');
      // $formSubmit.on('click', function () {
      //   $('form').submit();
      //   return false;
      // });


    })();
              
            
!
999px

Console