How to use
Copy-paste the following <script>
near the end of your pages under JS Implementing Plugins to enable it.
<script src="./assets/vendor/shufflejs/dist/shuffle.js"></script>
Copy-paste the init function under JS Plugins Init., before the closing </body>
tag, to enable it.
<script>
(function() {
// INITIALIZATION OF SHUFFLE
// =======================================================
class ShufflePorfolio {
constructor(element) {
this.element = element;
this.shuffle = new Shuffle(element, {
itemSelector: '.js-shuffle-item',
speed: 500
})
this.addFilterButtons()
}
addFilterButtons() {
const options = document.querySelector('.js-filter-options')
if (!options) {
return
}
const filterButtons = Array.from(options.children)
const onClick = this._handleFilterClick.bind(this)
filterButtons.forEach((button) => {
button.addEventListener('click', onClick, false)
});
}
_handleFilterClick(evt) {
const btn = evt.currentTarget.firstElementChild
const isActive = btn.classList.contains('active')
const btnGroup = btn.getAttribute('data-group')
this._removeActiveClassFromChildren(btn.parentNode.parentNode)
let filterGroup
if (isActive) {
btn.classList.remove('active')
filterGroup = Shuffle.ALL_ITEMS
} else {
btn.classList.add('active')
filterGroup = btnGroup
}
this.shuffle.filter(filterGroup)
}
_removeActiveClassFromChildren(parent) {
const { children } = parent
for (let i = children.length - 1; i >= 0; i--) {
children[i].firstElementChild.classList.remove('active')
}
}
}
new ShufflePorfolio(document.querySelector('.js-shuffle'))
});
</script>
Basic example
<div class="d-flex justify-content-center mb-5">
<!-- Nav -->
<ul class="js-filter-options nav nav-link-gray nav-lg" id="portfolioTab" role="tablist">
<li class="nav-item" role="presentation">
<a class="nav-link active" href="javascript:;" data-group="all">All</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" href="javascript:;" data-group="branding">Branding</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" href="javascript:;" data-group="development">Development</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" href="javascript:;" data-group="product-design">Product Design</a>
</li>
</ul>
<!-- End Nav -->
</div>
<div class="js-shuffle row row-cols-1 row-cols-sm-2 row-cols-md-3">
<div class="js-shuffle-item col-sm-6 mb-5" data-groups='["branding"]'>
<!-- Card -->
<a class="card card-flush card-transition" href="../portfolio-case-study.html">
<img class="card-img-top" src="../assets/img/600x650/img1.jpg" alt="Image Description">
<div class="card-body">
<span class="card-subtitle text-body">Branding</span>
<h5 class="card-title">Hondo Loggy</h5>
</div>
</a>
<!-- End Card -->
</div>
<!-- End Col -->
<div class="js-shuffle-item col-sm-6 mb-5" data-groups='["development"]'>
<!-- Card -->
<a class="card card-flush card-transition" href="../portfolio-case-study.html">
<img class="card-img-top" src="../assets/img/600x650/img2.jpg" alt="Image Description">
<div class="card-body">
<span class="card-subtitle text-body">Development</span>
<h5 class="card-title">Wibbitz</h5>
</div>
</a>
<!-- End Card -->
</div>
<!-- End Col -->
<div class="js-shuffle-item col-sm-6 mb-5" data-groups='["product-design"]'>
<!-- Card -->
<a class="card card-flush card-transition" href="../portfolio-case-study.html">
<img class="card-img-top" src="../assets/img/600x650/img3.jpg" alt="Image Description">
<div class="card-body">
<span class="card-subtitle text-body">Product Design</span>
<h5 class="card-title">The Hub</h5>
</div>
</a>
<!-- End Card -->
</div>
<!-- End Col -->
<div class="js-shuffle-item col-sm-6 mb-5" data-groups='["product-design"]'>
<!-- Card -->
<a class="card card-flush card-transition" href="../portfolio-case-study.html">
<img class="card-img-top" src="../assets/img/600x650/img4.jpg" alt="Image Description">
<div class="card-body">
<span class="card-subtitle text-body">Product Design</span>
<h5 class="card-title">Starbucks</h5>
</div>
</a>
<!-- End Card -->
</div>
<!-- End Col -->
<div class="js-shuffle-item col-sm-6 mb-5" data-groups='["product"]'>
<!-- Card -->
<a class="card card-flush card-transition" href="../portfolio-case-study.html">
<img class="card-img-top" src="../assets/img/600x650/img5.jpg" alt="Image Description">
<div class="card-body">
<span class="card-subtitle text-body">Product Design</span>
<h5 class="card-title">TATT</h5>
</div>
</a>
<!-- End Card -->
</div>
<!-- End Col -->
<div class="js-shuffle-item col-sm-6 mb-5" data-groups='["branding"]'>
<!-- Card -->
<a class="card card-flush card-transition" href="../portfolio-case-study.html">
<img class="card-img-top" src="../assets/img/600x650/img8.jpg" alt="Image Description">
<div class="card-body">
<span class="card-subtitle text-body">Branding</span>
<h5 class="card-title">Slack Agency</h5>
</div>
</a>
<!-- End Card -->
</div>
<!-- End Col -->
</div>
<!-- End Row -->