「javascript/test」の編集履歴(バックアップ)一覧に戻る

javascript/test - (2017/11/29 (水) 11:30:53) のソース

#js(){{{{{
<style>
#tabs {
  margin-top: 50px;
  padding-bottom: 40px;
  background-color: #fff;
  box-shadow: 0 0 10px rgba(0,0,0,0.2);
  width: 840px;
  margin 0 auto;
}

.tab_item {
  height: 50px;
  border-bottom: 3px solid #148;
  background-color: #def;
  line-height: 50px;
  font-size: 16px;
  text-align: center;
  color: #565656;
  display: block;
  float: left;
  text-align: center;
  font-weight: bold;
  transition: all 0.2s ease;
}
.tab_item:hover {
  opacity: 0.75;
}
input[name="tab_item"] {
  display:none;
}
#tabs> [id^="tab_content"] {
  padding: 40px 40px 0;
  clear: both;
  overflow: hidden;
  display: none;
}

#btn1:checked ~ #tab_content1,
#btn2:checked ~ #tab_content2,
#btn3:checked ~ #tab_content3,
#btn4:checked ~ #tab_content4,
#btn5:checked ~ #tab_content5 {
  display: block;
}

#tabs input:checked + .tab_item {
  background-color: #148;
  color: #fff;
}
</style>
<script type="text/javascript">
$(function(){
    var target = $('#tab_menu');
    var captions = $.trim(target.text()).split(',');
    for (var i = captions.length; i > 0; i--) {
        target.after($('<label class="tab_item">').attr('for', 'btn'+i).css('width', 'calc(100%/'+captions.length+')').text(captions[i-1]));
        target.after($('<input type="radio" name="tab_item">').attr('id', 'btn'+i).prop('checked', i == 1));
    }
    target.remove();
});
</script>
}}}}}