Convert Figma logo to code with AI

Vestride logoShuffle

Categorize, sort, and filter a responsive grid of items

2,367
282
2,367
22

Top Related Projects

Animate elements as they scroll into view.

11,041

:revolving_hearts: Filter & sort magical layouts

16,381

:love_hotel: Cascading grid layout plugin

Turbolinks makes navigating your web application faster

49,575

JavaScript animation engine

A lightweight carousel library with fluid motion and great swipe precision.

Quick Overview

Shuffle.js is a lightweight JavaScript library for dynamically sorting, filtering, and laying out a group of items. It's particularly useful for creating responsive, filterable galleries or grids of content. The library is flexible, customizable, and works well with modern JavaScript frameworks.

Pros

  • Easy to implement and integrate with existing projects
  • Supports responsive layouts and various grid systems
  • Provides smooth animations for sorting and filtering
  • Lightweight and performant, with no dependencies

Cons

  • Limited built-in layout options compared to some alternatives
  • May require additional CSS for more complex layouts
  • Documentation could be more comprehensive
  • Not as feature-rich as some larger grid/gallery libraries

Code Examples

  1. Basic initialization:
const element = document.querySelector('.my-shuffle-container');
const sizer = element.querySelector('.my-sizer-element');

const shuffleInstance = new Shuffle(element, {
  itemSelector: '.shuffle-item',
  sizer: sizer
});
  1. Filtering items:
shuffleInstance.filter('nature');
  1. Sorting items:
shuffleInstance.sort({
  by: (element) => element.getAttribute('data-created-date')
});
  1. Updating the shuffle instance after adding new items:
const newItems = document.querySelectorAll('.new-shuffle-items');
shuffleInstance.add(newItems);

Getting Started

  1. Install Shuffle.js:
npm install shufflejs
  1. Import and initialize Shuffle in your JavaScript:
import Shuffle from 'shufflejs';

const element = document.querySelector('.shuffle-container');
const shuffleInstance = new Shuffle(element, {
  itemSelector: '.shuffle-item'
});

// Add event listeners for filtering
document.querySelector('.filter-btn').addEventListener('click', (evt) => {
  const filterValue = evt.currentTarget.getAttribute('data-filter');
  shuffleInstance.filter(filterValue);
});
  1. Add the necessary HTML structure:
<div class="shuffle-container">
  <div class="shuffle-item" data-groups='["nature"]'>Item 1</div>
  <div class="shuffle-item" data-groups='["city"]'>Item 2</div>
  <div class="shuffle-item" data-groups='["nature"]'>Item 3</div>
</div>
<button class="filter-btn" data-filter="nature">Show Nature</button>
<button class="filter-btn" data-filter="city">Show City</button>

Competitor Comparisons

Animate elements as they scroll into view.

Pros of ScrollReveal

  • Focused on scroll-based animations, providing a more specialized solution for revealing elements as users scroll
  • Offers a wider range of animation options and customization for scroll-triggered effects
  • Smaller file size, making it more lightweight for projects primarily needing scroll animations

Cons of ScrollReveal

  • Limited to scroll-based animations, lacking the flexibility for other types of element manipulation
  • May require additional libraries or custom code for non-scroll related dynamic content changes

Code Comparison

ScrollReveal:

ScrollReveal().reveal('.element', {
    delay: 200,
    distance: '50px',
    origin: 'bottom',
    duration: 1000
});

Shuffle:

const shuffleInstance = new Shuffle(element, {
    itemSelector: '.shuffle-item',
    sizer: '.my-sizer-element'
});
shuffleInstance.filter('nature');

Summary

ScrollReveal excels in creating scroll-based animations with a wide range of customization options, while Shuffle is more versatile for general element manipulation and filtering. ScrollReveal is ideal for projects focused on scroll effects, whereas Shuffle offers broader functionality for dynamic content organization and filtering. The choice between the two depends on the specific needs of the project and the desired user interactions.

11,041

:revolving_hearts: Filter & sort magical layouts

Pros of Isotope

  • More comprehensive filtering and sorting options
  • Supports multiple layout modes (masonry, fitRows, etc.)
  • Larger community and ecosystem with extensive documentation

Cons of Isotope

  • Commercial license required for many use cases
  • Larger file size and potentially higher performance overhead
  • Steeper learning curve due to more complex API

Code Comparison

Isotope:

$('.grid').isotope({
  itemSelector: '.grid-item',
  layoutMode: 'masonry'
});

Shuffle:

var Shuffle = window.Shuffle;
var element = document.querySelector('.my-shuffle-container');
var shuffleInstance = new Shuffle(element, {
  itemSelector: '.shuffle-item'
});

Key Differences

  • Isotope offers more built-in layout options, while Shuffle focuses on filtering and sorting
  • Shuffle is free for commercial use, whereas Isotope requires a paid license for commercial projects
  • Isotope has a jQuery dependency, while Shuffle is a vanilla JavaScript library
  • Shuffle has a smaller file size and may be more performant for simpler use cases
  • Isotope provides more advanced features like stagger effects and infinite scroll support

Both libraries are capable of creating responsive, filterable, and sortable layouts, but they cater to different project needs and complexity levels. Choose based on your specific requirements, budget constraints, and desired features.

16,381

:love_hotel: Cascading grid layout plugin

Pros of Masonry

  • More mature and widely adopted project with a larger community
  • Supports a wider range of layout options and configurations
  • Better performance for large numbers of elements

Cons of Masonry

  • Larger file size and potentially more complex to implement
  • Less frequent updates and maintenance in recent years
  • Requires jQuery as a dependency (unless using the vanilla JS version)

Code Comparison

Masonry:

var grid = document.querySelector('.grid');
var msnry = new Masonry(grid, {
  itemSelector: '.grid-item',
  columnWidth: 200
});

Shuffle:

var Shuffle = window.Shuffle;
var element = document.querySelector('.my-shuffle-container');
var shuffleInstance = new Shuffle(element, {
  itemSelector: '.picture-item'
});

Both libraries offer similar functionality for creating dynamic grid layouts, but Masonry focuses on a "masonry" style layout, while Shuffle provides more flexibility in terms of filtering and sorting. Masonry is generally better suited for complex layouts with varying element sizes, while Shuffle excels in scenarios where you need to frequently update, filter, or sort the grid items.

Turbolinks makes navigating your web application faster

Pros of Turbolinks

  • Improves page load performance by replacing the full page load with partial updates
  • Seamlessly integrates with Ruby on Rails applications
  • Maintains a consistent JavaScript environment across page changes

Cons of Turbolinks

  • Can introduce complexity in handling JavaScript events and DOM manipulation
  • May require additional configuration for certain JavaScript libraries
  • Limited control over specific elements during page transitions

Code Comparison

Turbolinks (JavaScript):

document.addEventListener("turbolinks:load", function() {
  // Your initialization code here
});

Shuffle (JavaScript):

var shuffleInstance = new Shuffle(element, {
  itemSelector: '.picture-item',
  sizer: '.my-sizer-element',
});

Key Differences

  • Turbolinks focuses on improving page load performance for web applications
  • Shuffle is a library for shuffling, sorting, and filtering grid layouts
  • Turbolinks operates on the entire page, while Shuffle works with specific grid elements
  • Shuffle provides more granular control over individual elements and their transitions
  • Turbolinks is often used in server-rendered applications, while Shuffle is typically used in client-side JavaScript applications

Use Cases

  • Use Turbolinks for improving overall page load performance in web applications
  • Choose Shuffle for creating dynamic, filterable, and sortable grid layouts
  • Turbolinks is ideal for Ruby on Rails projects or similar server-rendered applications
  • Shuffle is better suited for portfolio websites, image galleries, or product catalogs with grid layouts
49,575

JavaScript animation engine

Pros of anime

  • Lightweight and flexible JavaScript animation library
  • Supports a wide range of animation types and properties
  • Provides a powerful timeline feature for complex animations

Cons of anime

  • Focused solely on animations, lacking Shuffle's layout capabilities
  • May require more manual setup for certain effects compared to Shuffle's built-in options
  • Less suitable for creating responsive grid layouts

Code Comparison

anime:

anime({
  targets: '.element',
  translateX: 250,
  rotate: '1turn',
  duration: 800,
  easing: 'easeInOutQuad'
});

Shuffle:

const shuffleInstance = new Shuffle(element, {
  itemSelector: '.shuffle-item',
  sizer: '.my-sizer-element',
});
shuffleInstance.filter('nature');

Key Differences

  • anime is primarily an animation library, while Shuffle focuses on grid layouts and filtering
  • Shuffle provides built-in functionality for creating and managing responsive, filterable grids
  • anime offers more flexibility in creating complex animations and timelines
  • Shuffle is better suited for projects requiring dynamic content organization and filtering
  • anime is more appropriate for projects with advanced animation requirements

Both libraries serve different purposes and can be complementary in certain projects, with anime handling animations and Shuffle managing layout and filtering.

A lightweight carousel library with fluid motion and great swipe precision.

Pros of Embla Carousel

  • Lightweight and performant, with a focus on smooth animations and touch interactions
  • Supports multiple slides per view and responsive breakpoints
  • Extensive API and plugin system for customization

Cons of Embla Carousel

  • Limited to carousel/slider functionality, less versatile than Shuffle
  • Steeper learning curve due to more complex API and configuration options

Code Comparison

Embla Carousel:

const embla = EmblaCarousel(emblaNode, { loop: false })
embla.on('select', () => {
  console.log(`Current index is ${embla.selectedScrollSnap()}`)
})

Shuffle:

const shuffle = new Shuffle(element, {
  itemSelector: '.picture-item',
  sizer: '.my-sizer-element',
})
shuffle.filter('nature')

Key Differences

  • Shuffle is a filtering and sorting library, while Embla Carousel is specifically for creating carousels
  • Embla Carousel offers more advanced carousel features, such as infinite looping and autoplay
  • Shuffle provides a simpler API for filtering and sorting elements, making it easier to implement for those specific use cases

Both libraries have their strengths, with Embla Carousel excelling in carousel functionality and Shuffle offering versatile filtering and sorting capabilities. The choice between them depends on the specific project requirements and desired features.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Shuffle Build Status Dependabot Status NPM version

Categorize, sort, and filter a responsive grid of items.

npm install shufflejs

Docs and Demos

All found here

Usage (with ES6)

import Shuffle from 'shufflejs';

const shuffleInstance = new Shuffle(document.getElementById('grid'), {
  itemSelector: '.js-item',
  sizer: '.js-shuffle-sizer',
});

Inspiration

This project was inspired by Isotope and Packery.

NPM DownloadsLast 30 Days