Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

muuri

> 编程语言
Open source

Infinite responsive, sortable, filterable and draggable layouts

10.9K stars0 likes4 views
WebsiteGitHub

About

Infinite responsive, sortable, filterable and draggable layouts

Muuri is a JavaScript layout engine that allows you to build all kinds of layouts (no kidding!) and make them responsive, sortable, filterable, draggable and/or animated. Comparing to what's out there Muuri is a combination of Packery, Masonry, Isotope and Sortable. Wanna see it in action? Check out the demo on the website.

Features

  • Fully customizable layout
  • Asynchronous layout calculations in web workers
  • Drag & drop (even between grids)
  • Auto-scrolling during drag
  • Nested grids
  • Fast animations
  • Filtering
  • Sorting

# Table of contents

  • Motivation
  • Getting started
  • API
    • Grid constructor
    • Grid options
    • Grid methods
    • Grid events
    • Item methods
  • Credits
  • License

# Motivation

You can build pretty amazing layouts without a single line of JavaScript these days. However, sometimes (rarely though) CSS just isn't enough, and that's where Muuri comes along. At it's very core Muuri is a layout engine which is limited only by your imagination. You can seriously build any kind of layout, asynchronously in web workers if you wish.

Custom layouts aside, you might need to sprinkle some flare (animation) and/or interactivity (filtering / sorting / drag & drop) on your layout (be it CSS or JS based). Stuff gets complex pretty fast and most of us probably reach for existing libraries to handle the complexity at that point. This is why most of these extra features are built into Muuri's core, so you don't have to go hunting for additional libraries or re-inventing the wheel for the nth time.

The long-term goal of Muuri is to provide a simple (and as low-level as possible) API for building amazing layouts with unmatched performance and most of the complexity abstracted away.

# Getting started

# 1. Get Muuri

Install via npm:

bash
npm install muuri

Or download:

  • muuri.js - for development (not minified, with comments).
  • muuri.min.js - for production (minified, no comments).

Or link directly:

xml
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/muuri.min.js"></script>

# 2. Get Web Animations Polyfill (if needed)

Muuri uses Web Animations to handle all the animations by default. If you need to use Muuri on a browser that does not support Web Animations you need to use a polyfill.

Install via npm:

bash
npm install web-animations-js

Or download:

  • web-animations.min.js

Or link directly:

xml
<script src="https://cdn.jsdelivr.net/npm/[email protected]/web-animations.min.js"></script>

# 3. Add the markup

  • Every grid must have a container element (referred as the grid element from now on).
  • Grid items must always consist of at least two elements. The outer element is used for positioning the item and the inner element (first direct child) is used for animating the item's visibility (show/hide methods). You can insert any markup you wish inside the inner item element.
  • Note that the class names in the below example are not required by Muuri at all, they're just there for example's sake.
xml

  </div>

  

      
    </div>
  </div>
</div>

# 4. Add the styles

  • The grid element must be "positioned" meaning that it's CSS position property must be set to relative, absolute or fixed. Also note that Muuri automatically resizes the grid element's width/height depending on the area the items cover and the layout algorithm configuration.
  • The item elements must have their CSS position set to absolute.
  • The item elements must not have any CSS transitions or animations applied to them, because they might conflict with Muuri's internal animation engine. However, the grid element can have transitions applied to it if you want it to animate when it's size changes after the layout operation.
  • You can control the gaps between the items by giving some margin to the item elements.
  • One last thing. Never ever set overflow: auto; or overflow: scroll; to the grid element. Muuri's calculation logic does not account for that and you will see some item jumps when dragging starts. Always use a wrapper element for the grid element where you set the auto/scroll overflow values.
css
.grid {
  position: relative;
}
.item {
  display: block;
  position: absolute;
  width: 100px;
  height: 100px;
  margin: 5px;
  z-index: 1;
  background: #000;
  color: #fff;
}
.item.muuri-item-dragging {
  z-index: 3;
}
.item.muuri-item-releasing {
  z-index: 2;
}
.item.muuri-item-hidden {
  z-index: 0;
}
.item-content {
  position: relative;
  width: 100%;
  height: 100%;
}

# 5. Fire it up

The bare minimum configuration is demonstrated below. You must always provide the grid element (or a selector so Muuri can fetch the element for you), everything else is optional.

javascript
var grid = new Muuri('.grid');

You can view this little tutorial demo here. After that you might want to check some other demos as well.

# API

# Grid constructor

Muuri is a constructor function and should be always instantiated with the new keyword. For the sake of clarity, we refer to a Muuri instance as grid throughout the documentation.

Syntax

Muuri( element, [options] )

Parameters

  • element  —  element / string
    • Default value: null.
    • You can provide the element directly or use a selector (string) which uses querySelector() internally.
  • options  —  object
    • Optional. Check out the detailed options reference.

Default options

The default options are stored in Muuri.defaultOptions object, which in it's default state contains the following configuration:

…

You can modify the default options easily:

javascript
Muuri.defaultOptions.showDuration = 400;
Muuri.defaultOptions.dragSortPredicate.action = 'swap';

This is how you would use the options:

javascript
// Minimum configuration.
var gridA = new Muuri('.grid-a');

// Providing some options.
var gridB = new Muuri('.grid-b', {
  items: '.item',
});

# Grid options

  • items
  • showDuration
  • showEasing
  • hideDuration
  • hideEasing
  • visibleStyles
  • hiddenStyles
  • layout
  • layoutOnResize
  • layoutOnInit
  • layoutDuration
  • layoutEasing
  • sortData
  • dragEnabled
  • dragContainer
  • dragHandle
  • dragStartPredicate
  • dragAxis
  • dragSort
  • dragSortHeuristics
  • dragSortPredicate
  • dragRelease
  • dragCssProps
  • dragPlaceholder
  • dragAutoScroll
  • containerClass
  • itemClass
  • itemVisibleClass
  • itemHiddenClass
  • itemPositioningClass
  • itemDraggingClass
  • itemReleasingClass
  • itemPlaceholderClass

# option: items

The initial item elements, which should be children of the grid element. All elements that are not children of the grid element (e.g. if they are not in the DOM yet) will be appended to the grid element. You can provide an array of elements, NodeList, HTMLCollection or a selector (string). If you provide a selector Muuri uses it to filter the current child elements of the container element and sets them as initial items. By default all current child elements of the provided grid element are used as initial items.

  • Default value: '*'.
  • Accepted types: array (of elements), NodeList, HTMLCollection, string, null.

Examples

javascript
// Use specific items.
var grid = new Muuri(elem, {
  items: [elemA, elemB, elemC],
});

// Use node list.
var grid = new Muuri(elem, {
  items: elem.querySelectorAll('.item'),
});

// Use selector.
var grid = new Muuri(elem, {
  items: '.item',
});

# option: showDuration

Show animation duration in milliseconds. Set to 0 to disable show animation.

  • Default value: 300.
  • Accepted types: number.

Examples

javascript
var grid = new Muuri(elem, {
  showDuration: 600,
});

# option: showEasing

Show animation easing. Accepts any valid Animation easing value.

  • Default value: 'ease'.
  • Accepted types: string.

Examples

javascript
var grid = new Muuri(elem, {
  showEasing: 'cubic-bezier(0.215, 0.61, 0.355, 1)',
});

# option: hideDuration

Hide animation duration in milliseconds. Set to 0 to disable hide animation.

  • Default value: 300.
  • Accepted types: number.

Examples

javascript
var grid = new Muuri(elem, {
  hideDuration: 600,
});

# option: hideEasing

Hide animation easing. Accepts any valid [Animation easing](https://developer.mozilla.org/en-US/docs

Issues· 117 open

View all issuesOpen on GitHub
  • #578

    Drag over same element and append more text

    Updated Jul 16, 2025
  • #576

    dragStart event is fired a second time just before the dragEnd event

    Updated Apr 23, 2025
  • #562

    Muuri Doesn't Work on Tailwindcss Classe

    Updated Mar 14, 2025
  • #561

    throws an error "window is not defined"

    Updated Jan 28, 2025
  • #574

    HTML link (<a> tag) in muuri grid, opening tab/window while drag and drop items

    Updated Dec 22, 2024
  • #572

    Resizing an item also drags/moves the item. (Tested and works up until 0.8.0, broke during and after 0.9.0)

    Updated Oct 30, 2024
  • #571

    Display a grid item in full screen

    Updated Oct 1, 2024
  • #570

    Adding and removing grids for drag and drop (not items)

    Updated Jun 7, 2024
  • #553

    dragSortPredicate does not seem to work properly

    Updated Apr 7, 2024
  • #551

    fillGaps property does not seem to work

    Updated Apr 7, 2024

> Tags

JavaScriptbin-packingdnddrag-and-dropdraggable

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 28, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言