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

              
                <!-- 絞り込みと -->
<div class="filterWrap">
  <!-- 絞り込み -->
  絞り込み 
  <select class="js-filter-options">
    <option value="">デフォルト</option>
    <option value="animal">animal</option>
    <option value="city">city</option>
    <option value="nature">nature</option>
  </select>

  <!-- ソート -->
  ソート 
  <select class="js-sort-options">
    <option value="">デフォルト</option>
    <option value="title">タイトル順</option>
    <option value="date-new">新しい順</option>
    <option value="date-old">古い順</option>
  </select>
</div>

<!-- フィルター対象の要素 -->
<div class="my-shuffle-container">
  <p class="item" data-groups='["animal"]' data-date-created="2012-08-12" data-title="Crocodile">
    groups:animal<br>
    date:2012-08-12<br>
    title:Crocodile
  </p>
  <p class="item" data-groups='["city"]' data-date-created="2016-06-09" data-title="Crossroads">
    groups:city<br>
    date:2016-06-09<br>
    title:Crossroads
  </p>
  <p class="item" data-groups='["nature","city"]' data-date-created="2015-10-20" data-title="Central Park">
    groups:nature,city<br>
    date:2015-10-20<br>
    title:Central Park
  </p>
  <p class="item" data-groups='["nature","city"]' data-date-created="2014-10-20" data-title="Central Park">
    groups:nature,city<br>
    date:2014-10-20<br>
    title:Central Park
  </p>
</div>

              
            
!

CSS

              
                .filterWrap{
  display: flex;
  background-color: #f1f1f1;
  padding: 30px;
  
  select{
    margin-right: 2em;
  }
}

.item {
  display:flex;
  align-items: center;
  justify-content: center;
  width: 180px;
  height: 180px;
  border: 1px solid #ddd;
}
              
            
!

JS

              
                // インスタンスを生成
const Shuffle = window.Shuffle;
const element = document.querySelector('.my-shuffle-container');

const shuffleInstance = new Shuffle(element, {
  itemSelector: '.item'
});

// 絞り込み
const getFilter = e =>{
  // 選択された要素のvalue属性の値を取得
  const value = e.target.value;
  // 取得した値で絞り込む
  shuffleInstance.filter(value);
}

// 絞り込みのselect要素が変更されたら実行する
const filterOptions = document.querySelectorAll('.js-filter-options');
const filterOptionsList = Array.prototype.slice.call(filterOptions, 0);
filterOptionsList.forEach(element => {
  element.addEventListener('change', getFilter, false);
});

// ソート
const getSort = e =>{
    const value = e.target.value;
    function sortByDate(e) {
      return e.getAttribute('data-date-created');
    }

    function sortByTitle(e) {
      return e.getAttribute('data-title').toLowerCase();
    }

    // 選択された内容によってソートのオプションを変える
    var options;
    if (value === 'date-new') {
      options = {
        reverse: true, // 降順
        by: sortByDate, // data-date-created属性の値を返す関数
      };
    } else if (value === 'date-old') {
      options = {
        reverse: false, // 昇順
        by: sortByDate, // data-date-created属性の値を返す関数
      };
    } else if (value === 'title') {
      options = {
        by: sortByTitle, // data-title属性の値を返す関数
      };
    } else {
      options = {};
    }
    // セットしたオプションでソートする
    shuffleInstance.sort(options);
}

// ソートのselect要素が変更されたら実行する
const sortOptions = document.querySelectorAll('.js-sort-options');
const sortOptionsList = Array.prototype.slice.call(sortOptions, 0);
sortOptionsList.forEach(element => {
  element.addEventListener('change', getSort , false);
});
              
            
!
999px

Console