Top Related Projects
:love_hotel: Cascading grid layout plugin
:revolving_hearts: Filter & sort magical layouts
React carousel component
Most modern mobile touch slider with hardware accelerated transitions
Quick Overview
Shuffle is a lightweight JavaScript library for randomly reordering DOM elements. It's designed to be flexible, performant, and easy to use, making it ideal for creating dynamic grid layouts, image galleries, or any other application where randomized element ordering is desired.
Pros
- Lightweight and fast, with minimal dependencies
- Supports responsive layouts and various grid systems
- Provides a simple API for easy integration
- Includes additional features like filtering and sorting
Cons
- Limited to DOM manipulation, not suitable for server-side shuffling
- May require additional setup for complex layouts or animations
- Documentation could be more comprehensive for advanced use cases
Code Examples
Basic shuffling of elements:
const shuffleInstance = new Shuffle(document.querySelector('.my-shuffle-container'));
shuffleInstance.shuffle();
Filtering elements based on a data attribute:
const shuffleInstance = new Shuffle(document.querySelector('.my-shuffle-container'));
document.querySelector('.filter-btn').addEventListener('click', () => {
shuffleInstance.filter('nature');
});
Sorting elements based on a custom sort function:
const shuffleInstance = new Shuffle(document.querySelector('.my-shuffle-container'));
shuffleInstance.sort({
by: (element) => parseInt(element.getAttribute('data-date-created'), 10),
});
Getting Started
- Install Shuffle via npm:
npm install shufflejs
- Import and initialize Shuffle in your JavaScript file:
import Shuffle from 'shufflejs';
const element = document.querySelector('.my-shuffle-container');
const shuffleInstance = new Shuffle(element, {
itemSelector: '.shuffle-item',
sizer: '.my-sizer-element',
});
- Add the necessary HTML structure:
<div class="my-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 class="my-sizer-element"></div>
</div>
Competitor Comparisons
: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, including vertical and horizontal layouts
- Better documentation and examples available
Cons of Masonry
- Larger file size and potentially slower performance for simple grid layouts
- Less frequent updates and maintenance compared to Shuffle
- More complex setup and configuration for basic use cases
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 provides more advanced options for complex layouts, while Shuffle focuses on simplicity and performance for basic grid arrangements. Masonry's code tends to be more verbose, while Shuffle aims for a more streamlined approach. The choice between the two depends on the specific requirements of your project and the level of customization needed.
:revolving_hearts: Filter & sort magical layouts
Pros of Isotope
- More comprehensive feature set, including filtering, sorting, and layout modes
- Larger community and longer development history, potentially leading to better stability
- Supports more layout options out of the box (e.g., masonry, fitRows, cellsByRow)
Cons of Isotope
- Commercial license required for many use cases, which may be cost-prohibitive
- Larger file size and potentially higher performance overhead
- Less frequent updates and maintenance compared to Shuffle
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: '.picture-item'
});
Key Differences
- Isotope offers more built-in layout options and features
- Shuffle is free and open-source, while Isotope requires a commercial license for many use cases
- Isotope has a jQuery-based API, while Shuffle uses vanilla JavaScript
- Shuffle has a smaller footprint and may be more performant for simpler use cases
- Isotope has a larger community and ecosystem of plugins and extensions
React carousel component
Pros of react-slick
- Specifically designed for React applications, offering seamless integration
- Extensive customization options for carousel/slider functionality
- Large community and active maintenance
Cons of react-slick
- Limited to carousel/slider functionality, less versatile than Shuffle
- May have a steeper learning curve for complex customizations
- Potentially heavier in terms of bundle size due to its feature-rich nature
Code Comparison
react-slick:
import React from "react";
import Slider from "react-slick";
const SimpleSlider = () => {
const settings = {
dots: true,
infinite: true,
speed: 500,
slidesToShow: 1,
slidesToScroll: 1
};
return (
<Slider {...settings}>
<div><h3>1</h3></div>
<div><h3>2</h3></div>
<div><h3>3</h3></div>
</Slider>
);
}
Shuffle:
import Shuffle from 'shufflejs';
const shuffleInstance = new Shuffle(element, {
itemSelector: '.picture-item',
sizer: '.my-sizer-element',
});
shuffleInstance.filter('nature');
shuffleInstance.sort({ by: getDataAttribute });
While react-slick focuses on creating responsive carousels with various transition effects, Shuffle provides a more general-purpose solution for filtering, sorting, and animating grid layouts. The choice between the two depends on the specific requirements of your project.
Most modern mobile touch slider with hardware accelerated transitions
Pros of Swiper
- More comprehensive feature set, including support for various types of sliders and carousels
- Extensive documentation and active community support
- Mobile-friendly with touch support out of the box
Cons of Swiper
- Larger file size and potentially higher performance overhead
- Steeper learning curve due to more complex API and configuration options
- May be overkill for simple grid layouts or filtering tasks
Code Comparison
Swiper initialization:
const swiper = new Swiper('.swiper-container', {
slidesPerView: 3,
spaceBetween: 30,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
});
Shuffle initialization:
const shuffleInstance = new Shuffle(element, {
itemSelector: '.shuffle-item',
sizer: '.my-sizer-element',
});
While Swiper focuses on creating interactive sliders and carousels, Shuffle is primarily designed for filtering and sorting grid layouts. Swiper offers more advanced features for creating dynamic slideshows, whereas Shuffle excels in managing and animating grid-based content with filtering capabilities. The choice between the two depends on the specific requirements of your project.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Shuffle
Categorize, sort, and filter a responsive grid of items.
npm install shufflejs
Docs and Demos
Usage (with ES6)
import Shuffle from 'shufflejs';
const shuffleInstance = new Shuffle(document.getElementById('grid'), {
itemSelector: '.js-item',
sizer: '.js-shuffle-sizer',
});
Inspiration
Top Related Projects
:love_hotel: Cascading grid layout plugin
:revolving_hearts: Filter & sort magical layouts
React carousel component
Most modern mobile touch slider with hardware accelerated transitions
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot