123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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.

            
              <div class="demo-cover">
 
<div class="nav-wrap">
    <nav class="nav" id="nav">
      <ul class="nav-list">
        <li>
          <div class="nav-list-front">
            <div class="nav-list-ttl">Category</div>
            <div class="nav-show-all" id="nav-show-all">
              <input type="radio" id="nav-input-all" name="nav-input" class="nav-input" data-sort-nav="show-all" checked>
              <label for="nav-input-all" id="show-all" class="nav-child-inner">
                全て見る</span></div>
              </label>
            </div>
          </div>
          <ul class="nav-child">
            <li>
              <input type="radio" id="nav-input-fruits" name="nav-input" class="nav-input" data-sort-nav="fruits">
              <label for="nav-input-fruits" id="fruits" class="nav-child-inner">
                <div class="nav-txt">くだもの</div>
              </label>
            </li>
            <li>
              <input type="radio" id="nav-input-vegetables" name="nav-input" class="nav-input" data-sort-nav="vegetables">
              <label for="nav-input-vegetables" id="vegetables" class="nav-child-inner">
                <div class="nav-txt">野菜</div>
              </label>
            </li>
            <li>
              <input type="radio" id="nav-input-meat" name="nav-input" class="nav-input" data-sort-nav="meat">
              <label for="nav-input-meat" id="meat" class="nav-child-inner">
                <div class="nav-txt">肉</div>
              </label>
            </li>
            <li>
              <input type="radio" id="nav-input-fish" name="nav-input" class="nav-input" data-sort-nav="fish">
              <label for="nav-input-fish" id="fish" class="nav-child-inner">
                <div class="nav-txt">魚</div>
              </label>
            </li>
            <li>
              <input type="radio" id="nav-input-dairy-products" name="nav-input" class="nav-input" data-sort-nav="dairy-products">
              <label for="nav-input-dairy-products" id="cereals" class="nav-child-inner">
                <div class="nav-txt">乳製品</div>
              </label>
            </li>
          </ul>
        </li>
      </ul>
    </nav>
    <div class="sort-block">
     <div class="sort-ttl" id="sort-ttl">Show all</div>
     <ul class="sort-list" id="sort-list">
      <li data-sort-item="fruits" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>りんご</p>
          </div>
          <div class="sort-list-category">
            <span>くだもの</span>
          </div>
        </div>
      </li>
      <li data-sort-item="fish" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>アジ</p>
          </div>
          <div class="sort-list-category">
            <span>魚</span>
          </div>
        </div>
      </li>
      <li data-sort-item="fruits,vegetables" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>唐辛子</p>
          </div>
          <div class="sort-list-category">
            <span>くだもの</span>
            <span>野菜</span>
          </div>
        </div>
      </li>
      <li data-sort-item="meat" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>豚肉</p>
          </div>
          <div class="sort-list-category">
            <span>肉</span>
          </div>
        </div>
      </li>
      <li data-sort-item="fruits,vegetables" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>なす</p>
          </div>
          <div class="sort-list-category">
            <span>くだもの</span>
            <span>野菜</span>
          </div>
        </div>
      </li>
      <li data-sort-item="fish" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>ブリ</p>
          </div>
          <div class="sort-list-category">
            <span>魚</span>
          </div>
        </div>
      </li>
       <li data-sort-item="fruits" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>いちご</p>
          </div>
          <div class="sort-list-category">
            <span>くだもの</span>
          </div>
        </div>
      </li>
      <li data-sort-item="vegetables" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>すいか</p>
          </div>
          <div class="sort-list-category">
            <span>野菜</span>
          </div>
        </div>
      </li>
      <li data-sort-item="meat" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>鶏肉</p>
          </div>
          <div class="sort-list-category">
            <span>肉</span>
          </div>
        </div>
      </li>
      <li data-sort-item="vegetables" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>ほうれん草</p>
          </div>
          <div class="sort-list-category">
            <span>野菜</span>
          </div>
        </div>
      </li>
      <li data-sort-item="fish" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>まぐろ</p>
          </div>
          <div class="sort-list-category">
            <span>魚</span>
          </div>
        </div>
      </li>
      <li data-sort-item="dairy-products" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>ヨーグルト</p>
          </div>
          <div class="sort-list-category">
            <span>乳製品</span>
          </div>
        </div>
      </li>
      <li data-sort-item="meat" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>ベーコン</p>
          </div>
          <div class="sort-list-category">
            <span>肉</span>
          </div>
        </div>
      </li>
      <li data-sort-item="dairy-products" class="is-selected">
        <div class="sort-list-inner">
          <div class="sort-list-ttl">
            <p>チーズ</p>
          </div>
          <div class="sort-list-category">
            <span>乳製品</span>
          </div>
        </div>
      </li>
    </ul>
  </div>
  </div>  
            
          
!
            
              //common
html{
  font-size:62.5%;
}
body{
  font-size:1.4rem;
}
ul,li{
  list-style-type:none;
  padding-left:0;
  margin-left:0;
}
.demo-cover{
  margin:0 auto;
  width:100%;
  max-width:800px;
}
//mixin
$color-bg:#f7f7f7;



//nav
.nav {
	padding: 25px 0px 15px;
	background: #fff;

}

.nav-cover {
	background: #fff;
	overflow: hidden;
	opacity: 1;
}

.nav-list-ttl {
	font-size: 1.5rem;
	font-weight: 500;
}

.nav-list {
	>li {
		margin-top: 25px;

		&:first-child {
			margin-top: 0;
		}
	}
}


.nav-child {
	display: flex;
	flex-wrap: wrap;
	margin-top: 10px;

	>li {
		width: 32%;
    margin-top:20px;
    margin-right:2%;
		text-align: center;
		display: flex;

		&:nth-child(3n) {
			margin-right:0;
		}
	}
}

.nav-icon {
	display: block;
	width: 100%;
	font-size: 4rem;
	color: #969696;
	transition: .3s;

	+.nav-txt {
		margin-top: 10px;

	}
}

.nav-txt {
	display: block;
	width: 100%;
	font-feature-settings: "palt";
	font-size: 1.2rem;
	transition: .3s;

	>span {
		display: inline-block;
		margin-right: 3px;
		width: 10px;
	}

}

.nav-child-inner {
	display: flex;
	flex-wrap: wrap;
  align-items:center;
	width: 100%;
	padding: 15px 10px;
	background: $color-bg;
	border-radius: 5px;
}

.nav-btn {
	display: none;
	position: absolute;
	right: 15px;
	top: 50%;
	transform: translateY(-50%);


	.icon-close {
		display: none;
		visibility: hidden;
		opacity: 0;
	}
}

.nav-list-front {
  display: flex;
	align-items: center;
	justify-content: space-between;
}

.nav-show-all {
	.nav-child-inner {
    text-align:center;
		font-size: 1.2rem;
		padding: 10px 20px;
		color: #636363;
    background: $color-bg;
		line-height: 1;
    box-sizing:border-box;
	}

	.nav-input {
		&:checked {
			+label {
				color: #fff;
			}
		}
	}
}


.sort-block{
  margin-top:60px;
}

.sort-ttl {
  font-size:1.8rem;
  font-weight:800;
		text-transform: lowercase;
		&:first-letter {
			text-transform: capitalize;
		}
}
//sort-list
.sort-list {
	margin-top: 30px;
	display: flex;
	flex-wrap: wrap;

	>li {
		width: 32%;
		min-height: 150px;
		margin-bottom: 24px;
		display: flex;
		background: #fff;
	}
}

.sort-list-cover {
	padding: 10px 0 15px;
	min-height: 190px;
}

.sort-list-head {
	padding: 0 10px;
}

.sort-list-inner {
	position: relative;
	width: 100%;
	height: 100%;
  border:1px solid #ddd;
  padding:10px;
  box-sizing:border-box;
}
.nav-input {
	display: none;

	&:checked {
		+label {
      background:#ddd;
			.nav-txt {
				color: #fff;
			}
		}
	}
}
.sort-list-ttl{
  font-size:1.6rem;
  text-align:center;
}
.sort-list-category{
  >span{
    display:inline-block;
    padding:5px 10px;
    border:1px solid #ddd;
    line-height:1;
    vertical-align:middle;
    border-radius:25px;
    box-sizing:border-box;
    +span{
      margin-left:5px;
    }
  }
}
//state

//sort-list
.sort-list {
	>li {
		display: none;
		animation: sort_clear .5s ease -.3s 1 normal;


		&.is-selected {
			display: flex;
      margin:0 .5% 1%;
			animation: sort_selected .5s ease -.1s 1 forwards;
		}
	}

}

@keyframes sort_clear {
	0% {
		opacity: 1;
		transform: scale(1);
	}

	99% {
		transform: scale(.7);
		opacity: 0;
	}

	100% {
		transform: scale(.7);
		opacity: 0;
	}
}

@keyframes sort_selected {
	0% {
		opacity: 0;
	}

	1% {
		opacity: 1;
		transform: scale(.7);

	}

	100% {
		transform: scale(1);
	}
}
            
          
!
            
              (function () {

  // ソート処理
  let clickSort;
  let clickScroll;
  let allShow;
  let sortTtlChange;
  const sortTtlNameArrey = []; //  data-sort-navを入れる配列

  const navInput = document.getElementsByClassName('nav-input');
  const sortList = document.getElementById('sort-list');
  const sortListLi = sortList.getElementsByTagName('li');
  const sortTtl = document.getElementById('sort-ttl');

  for (var i = 0; i < navInput.length; i++) {
    //  data-sort-navを配列に入れる
    sortTtlNameArrey.push(navInput[i].getAttribute('data-sort-nav'));
    // console.log(sortTtlNameArrey);

    (function (n) {

      // #sort-ttlを変更
      sortTtlChange = function (selectName) {
        let selectSortTtlName;

        // 全て表示
        if (selectName === 'show-all') {
          selectSortTtlName = 'Show all';
        } else {
          // sortTtlNameArreyにあてはまるものを探す
          for (var i = 0; i < sortTtlNameArrey.length; i++) {
            if (sortTtlNameArrey[i] == selectName) {
              selectSortTtlName = sortTtlNameArrey[i].replace('-', ' '); // アンダースコアをスペースに
              break;
            }
          }
        }
        // console.log(sortTtlName)
        const sortTtlName = selectSortTtlName;
        sortTtl.innerHTML = sortTtlName;
      };

      // すべて表示
      allShow = function (e) {
        for (var i = 0; i < sortListLi.length; i++) {
          sortListLi[i].classList.add('is-selected');
        }

      };

      // しぼりこみ表示
      clickSort = function (e) {
        const dataSortNav = e.currentTarget.getAttribute('data-sort-nav');

        // dataSortNavと同じ値を持っているものにclassをつける
        for (var i = 0; i < sortListLi.length; i++) {
          (function (n) {
            const sortListLiDataSortItem = sortListLi[n].getAttribute('data-sort-item');
            const sortListLiDataSortItemArrey = sortListLiDataSortItem.split(',');
            // console.log(sortListLiDataSortItemArrey);
            for (var a = 0; a < sortListLiDataSortItemArrey.length; a++) {
              if (sortListLiDataSortItemArrey[a] === dataSortNav) {
                sortListLi[i].classList.add('is-selected');
                break;
              } else {
                sortListLi[i].classList.remove('is-selected');
              }
            }
          })(i);
        }
      };

      navInput[n].addEventListener('click', function (e) {
        // すべて表示
        if (e.currentTarget.getAttribute('data-sort-nav') === 'show-all') {
          allShow(e);
        } else {
          // 絞り込み
          for (var i = 0; i < navInput.length; i++) {
            navInput[i].classList.remove('is-checked');
          }
          e.currentTarget.classList.add('is-checked');
          clickSort(e);
        }
        sortTtlChange(e.currentTarget.getAttribute('data-sort-nav'));

      }, false);
    })(i);
  }

}());

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console