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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                <p>セレクトボックスを選択してから矢印を押してください。</p>

<div class="selectbox">
  <div class="selectbox-inner">
    <div class="selectbox-from">
      <p class="selectbox-ttl">未選択</p>
      <select size="12" multiple="multiple" name="selectbox-select-from" id="selectbox-select-from">
        <option value="アメリカンショートヘア">アメリカンショートヘア</option>
        <option value="ベンガル">ベンガル</option>
        <option value="ロシアンブルー">ロシアンブルー</option>
        <option value="ラグドール">ラグドール</option>
      </select>
    </div>
    <div class="selectbox-control">
      <div class="selectbox-add">
        <button id="selectbox-add-btn" class="selectbox-add-btn" name="selectbox-add-btn">→</button>   
      </div>
      <div class="selectbox-remove">
        <button id="selectbox-remove-btn" class="selectbox-remove-btn" name="selectbox-remove-btn">←</button>
      </div>
    </div>
    <div class="selectbox-to">
      <p class="selectbox-ttl">選択済み</p>
      <select size="12" multiple="multiple" name="selectbox-select-to" id="selectbox-select-to">
        <option value="三毛猫">三毛猫</option>
        <option value="スフィンクス">スフィンクス</option>
        <option value="シャム">シャム</option>
        <option value="ペルシャ">ペルシャ</option> 
      </select>
    </div>
  </div>
</div>
                      
              
            
!

CSS

              
                html{
  font-size:62.5%;
  color:#333;
}
body{
  font-size:1.4rem;
}
//input
option{
  font-size:1.4rem;
}
//selectbox
.selectbox {
  select {
    width: 250px;
    padding: 5px;
  }
}

.selectbox-inner {
  display: flex;
  align-items: center;
}

.electbox-from {
  width: 250px;
}

.selectbox-control {
  width: 60px;
}

.selectbox-to {
  width: 250px;
}

.selectbox-ttl {
  font-weight: bold;
  font-size: 1.6rem;
}

.selectbox-remove {
  text-align: center;
  margin-top: 16px;
}

.selectbox-remove-btn {
  width: 35px;
  height: 35px;
  border-radius: 4px;
  border: solid 1px #ccc;
  color: #333;
  background: #fff;
  text-align: center;
  line-height: 35px;
  cursor:pointer;
}

.selectbox-add {
  text-align: center;
}

.selectbox-add-btn {
  width: 35px;
  height: 35px;
  border-radius: 4px;
  border: solid 1px #ccc;
  color: #333;
  background: #fff;
  text-align: center;
  line-height: 35px;
  cursor:pointer;
}
              
            
!

JS

              
                //選択ボックス selectbox
$(function () {
  var $selectboxSelectFrom = '#selectbox-select-from';
  var $selectboxSelectTo = '#selectbox-select-to';
  var $selectboxRemoveBtn = $('#selectbox-remove-btn');
  var $selectboxAddBtn = $('#selectbox-add-btn');
  var selectboxSelectFlg = true;
  var $selectboxSelectFromSelect; //$selectboxSelectFromで選ばれているもの
  var $selectboxSelectToSelect; //$selectboxSelectToで選ばれているもの

  if (0 < $selectboxSelectFrom.length && 0 < $selectboxSelectTo.length) {

    function selectMoved(clickBtn) {
      selectboxSelectFlg = false;
      $selectboxSelectFromSelect = $($selectboxSelectFrom).val();
      $selectboxSelectToSelect = $($selectboxSelectTo).val();


      var createOption;
      var removeOrAdd;
      var $selectboxSelectSelectForm;
      var action;

      var selectArray = [];

      if (clickBtn === $selectboxRemoveBtn) {
        removeOrAdd = $selectboxSelectToSelect;
        $selectboxSelectSelectForm = $($selectboxSelectTo + ' option:selected');
        action = 'remove';

      } else if (clickBtn === $selectboxAddBtn) {
        removeOrAdd = $selectboxSelectFromSelect;
        action = 'add';
        $selectboxSelectSelectForm = $($selectboxSelectFrom + ' option:selected');
      }
      
        //セレクトボックスで選択されているoptionのvalueとテキストを配列に入れる
      if (removeOrAdd === null) {
        //removeOrAddが空の場合は処理しない
      } else {
      //valとテキストを格納
        for (var i = 0; i < removeOrAdd.length; i++) {
          selectArray.push([removeOrAdd[i], $selectboxSelectSelectForm.eq(i).text()]);
        }
      }
      
      //選択されたoptionを削除し、反対側のselectにoptionを入れ込む
      function selectAppend(append,remove){
        //先ほど格納した配列selectArrayの個数分処理をまわす
          for (var a = 0; a < selectArray.length; a++) {
            createOption = '<option value="' + selectArray[a][0] + '">' + selectArray[a][1] + '</option>'; //optionを作成
            $(append).append(createOption);//反対側のselectにoptionを入れ込む
          }
          $(remove + ' option:selected').remove();//選択されたoptionを削除
      }


      if (action === 'remove') {
        //removeの時
        if (!($selectboxSelectToSelect === undefined)) { //undefinedなら処理しない
          selectAppend($selectboxSelectFrom, $selectboxSelectTo);
        }

      } else if (action === 'add') {
        //addの時
        if (!($selectboxSelectFromSelect === undefined)) { //undefinedなら処理しない
          selectAppend($selectboxSelectTo, $selectboxSelectFrom);
        }
      }
      selectboxSelectFlg = true;
    }

    $selectboxRemoveBtn.on('click', function () {
      if (selectboxSelectFlg) {
        selectMoved($selectboxRemoveBtn);
      }
    });
    $selectboxAddBtn.on('click', function () {
      if (selectboxSelectFlg) {
        selectMoved($selectboxAddBtn);

      }
    });
  }
});
              
            
!
999px

Console