mixitup.Config
mixitup.Config
is an interface used for customising the functionality of a
mixer instance. It is organised into several semantically distinct sub-objects,
each one pertaining to a particular aspect of MixItUp functionality.
An object literal containing any or all of the available properies,
known as the "configuration object", can be passed as the second parameter to
the mixitup
factory function when creating a mixer instance to customise its
functionality as needed.
If no configuration object is passed, the mixer instance will take on the default configuration values detailed below.
mixitup.Config.animation
A group of properties defining the mixer’s animation and effects settings.
enable
Type | Default |
---|---|
boolean | true |
A boolean dictating whether or not animation should be enabled for the MixItUp instance.
If false
, all operations will occur instantly and syncronously, although callback
functions and any returned promises will still be fulfilled.
effects
Type | Default |
---|---|
string | 'fade scale' |
A string of one or more space-seperated properties to which transitions will be applied for all filtering animations.
Properties can be listed any order or combination, although they will be applied in a specific predefined order to produce consistent results.
To learn more about available effects, experiment with our sandbox demo and try out the “Export config” button in the Animation options drop down.
effectsIn
Type | Default |
---|---|
string | '' |
A string of one or more space-seperated effects to be applied only to filter-in
animations, overriding config.animation.effects
if set.
effectsOut
Type | Default |
---|---|
string | '' |
A string of one or more space-seperated effects to be applied only to filter-out
animations, overriding config.animation.effects
if set.
duration
Type | Default |
---|---|
number | 600 |
An integer dictating the duration of all MixItUp animations in milliseconds, not
including any additional delay apllied via the 'stagger'
effect.
easing
Type | Default |
---|---|
string | 'ease' |
A valid CSS3 transition-timing function or shorthand. For a full list of accepted values, visit easings.net.
applyPerspective
Type | Default |
---|---|
bolean | true |
A boolean dictating whether or not to apply perspective to the MixItUp container
during animations. By default, perspective is always applied and creates the
illusion of three-dimensional space for effects such as translateZ
, rotateX
,
and rotateY
.
You may wish to disable this and define your own perspective settings via CSS.
perspectiveDistance
Type | Default |
---|---|
string | '3000px' |
The perspective distance value to be applied to the container during animations, affecting any 3D-transform-based effects.
perspectiveOrigin
Type | Default |
---|---|
string | '50% 50%' |
The perspective-origin value to be applied to the container during animations, affecting any 3D-transform-based effects.
queue
Type | Default |
---|---|
boolean | true |
A boolean dictating whether or not to enable the queuing of operations.
If true
(default), and a control is clicked or an API call is made while another
operation is progress, the operation will go into the queue and will be automatically exectuted
when the previous operaitons is finished.
If false
, any requested operations will be ignored, and the onMixBusy
callback and mixBusy
event will be fired. If debug.showWarnings
is enabled, a console warning will also occur.
queueLimit
Type | Default |
---|---|
number | 3 |
An integer dictacting the maximum number of operations allowed in the queue at any time, when queuing is enabled.
animateResizeContainer
Type | Default |
---|---|
boolean | true |
A boolean dictating whether or not to transition the height and width of the container as elements are filtered in and out. If disabled, the container height will change abruptly.
It may be desirable to disable this on mobile devices as the CSS height
and
width
properties do not receive GPU-acceleration and can therefore cause stuttering.
animateResizeTargets
Type | Default |
---|---|
boolean | false |
A boolean dictating whether or not to transition the height and width of target elements as they change throughout the course of an animation.
This is often a must for flex-box grid layouts where the size of target elements may change
depending on final their position in relation to their siblings, or for .changeLayout()
operations where the size of targets change between layouts.
NB: This feature requires additional calculations and manipulation to non-hardware-accelerated properties which may adversely affect performance on slower devices, and is therefore disabled by default.
staggerSequence
Type | Default |
---|---|
function | null |
A custom function used to manipulate the order in which the stagger delay is incremented when using the ‘stagger’ effect.
When using the ‘stagger’ effect, the delay applied to each target element is incremented based on its index. You may create a custom function to manipulate the order in which the delay is incremented and create engaging non-linear stagger effects.
The function receives the index of the target element as a parameter, and must return an integer which serves as the multiplier for the stagger delay.
reverseOut
Type | Default |
---|---|
boolean | false |
A boolean dictating whether or not to reverse the direction of translate
and rotate
transforms for elements being filtered out.
It can be used to create carousel-like animations where elements enter and exit
from opposite directions. If enabled, the effect translateX(-100%)
for elements
being filtered in would become translateX(100%)
for targets being filtered out.
This functionality can also be achieved by providing seperate effects
strings for config.animation.effectsIn
and config.animation.effectsOut
.
nudge
Type | Default |
---|---|
boolean | true |
A boolean dictating whether or not to “nudge” the animation path of targets when they are being filtered in and out simulatenously.
This has been the default behavior of MixItUp since version 1, but it may be desirable to disable this effect when filtering directly from one exclusive set of targets to a different exclusive set of targets, to create a carousel-like effect, or a generally more subtle animation.
clampHeight
Type | Default |
---|---|
boolean | true |
A boolean dictating whether or not to clamp the height of the container while MixItUp’s geometry tests are carried out before an operation.
To prevent scroll-bar flicker, clamping is turned on by default. But in the case where the height of the container might affect its vertical positioning in the viewport (e.g. a vertically-centered container), this should be turned off to ensure accurate test results and a smooth animation.
clampWidth
Type | Default |
---|---|
boolean | true |
A boolean dictating whether or not to clamp the width of the container while MixItUp’s geometry tests are carried out before an operation.
To prevent scroll-bar flicker, clamping is turned on by default. But in the case where the width of the container might affect its horitzontal positioning in the viewport (e.g. a horizontall-centered container), this should be turned off to ensure accurate test results and a smooth animation.
mixitup.Config.behavior
A group of properties relating to the behavior of the Mixer.
liveSort
Type | Default |
---|---|
boolean | false |
A boolean dictating whether to allow “live” sorting of the mixer.
Because of the expensive nature of sorting, MixItUp makes use of several internal optimizations to skip redundant sorting operations, such as when the newly requested sort command is the same as the active one. The caveat to this optimization is that “live” edits to the value of a target’s sorting attribute will be ignored when requesting a re-sort by the same attribute.
By setting to behavior.liveSort
to true
, the mixer will always re-sort
regardless of whether or not the sorting attribute and order have changed.
mixitup.Config.callbacks
A group of optional callback functions to be invoked at various points within the lifecycle of a mixer operation.
Each function is analogous to an event of the same name triggered from the container element, and is invoked immediately after it.
All callback functions receive the current state
object as their first
argument, as well as other more specific arguments described below.
onMixStart
Type | Default |
---|---|
function | null |
A callback function invoked immediately after any MixItUp operation is requested and before animations have begun.
A second futureState
argument is passed to the function which represents the final
state of the mixer once the requested operation has completed.
onMixBusy
Type | Default |
---|---|
function | null |
A callback function invoked when a MixItUp operation is requested while another operation is in progress, and the animation queue is full, or queueing is disabled.
onMixEnd
Type | Default |
---|---|
function | null |
A callback function invoked after any MixItUp operation has completed, and the state has been updated.
onMixFail
Type | Default |
---|---|
function | null |
A callback function invoked whenever an operation "fails", i.e. no targets could be found matching the requested filter.
onMixClick
Type | Default |
---|---|
function | null |
A callback function invoked whenever a MixItUp control is clicked, and before its respective operation is requested.
The clicked element is assigned to the this
keyword within the function. The original
click event is passed to the function as the second argument, which can be useful if
using <a>
tags as controls where the default behavior needs to be prevented.
Returning false
from the callback will prevent the control click from triggering
an operation.
mixitup.Config.controls
A group of properties relating to clickable control elements.
enable
Type | Default |
---|---|
boolean | true |
A boolean dictating whether or not controls should be enabled for the mixer instance.
If true
(default behavior), MixItUp will search the DOM for any clickable elements with
data-filter
, data-sort
or data-toggle
attributes, and bind them for click events.
If false
, no click handlers will be bound, and all functionality must therefore be performed
via the mixer’s API methods.
If you do not intend to use the default controls, setting this property to false
will
marginally improve the startup time of your mixer instance, and will also prevent any other active
mixer instances in the DOM which are bound to controls from controlling the instance.
live
Type | Default |
---|---|
boolean | true |
A boolean dictating whether or not to use event delegation when binding click events to the default controls.
If false
(default behavior), each control button in the DOM will be found and
individually bound when a mixer is instantiated, with their corresponding actions
cached for performance.
If true
, a single click handler will be applied to the window
(or container element - see
config.controls.scope
), and any click events triggered by elements with data-filter
,
data-sort
or data-toggle
attributes present will be handled as they propagate upwards.
If you require a user interface where control buttons may be added, removed, or changed during the
lifetime of a mixer, controls.live
should be set to true
. There is a marginal but unavoidable
performance deficit when using live controls, as the value of each control button must be read
from the DOM in real time once the click event has propagated.
scope
Type | Default |
---|---|
string | 'global' |
A string dictating the “scope” to use when binding or querying the default controls. The available
values are 'global'
or 'local'
.
When set to 'global'
(default behavior), MixItUp will query the entire document for control buttons
to bind, or delegate click events from (see config.controls.live
).
When set to 'local'
, MixItUp will only query (or bind click events to) its own container element.
This may be desireable if you require multiple active mixer instances within the same document, with
controls that would otherwise intefere with each other if scoped globally.
Conversely, if you wish to control multiple instances with a single UI, you would create one
set of controls and keep the controls scope of each mixer set to global
.
toggleLogic
Type | Default |
---|---|
string | 'or' |
A string dictating the type of logic to apply when concatenating the filter selectors of
active toggle buttons (i.e. any clickable element with a data-toggle
attribute).
If set to 'or'
(default behavior), selectors will be concatenated together as
a comma-seperated list. For example:
'.cat-1, .cat-2'
(shows any elements matching '.cat-1'
OR '.cat-2'
)
If set to 'and'
, selectors will be directly concatenated together. For example:
'.cat-1.cat-2'
(shows any elements which match both '.cat-1'
AND '.cat-2'
)
toggleDefault
Type | Default |
---|---|
string | 'all' |
A string dictating the filter behavior when all toggles are inactive.
When set to 'all'
(default behavior), all targets will be shown by default
when no toggles are active, or at the moment all active toggles are toggled off.
When set to 'none'
, no targets will be shown by default when no toggles are
active, or at the moment all active toggles are toggled off.
mixitup.Config.classNames
A group of properties defining the output and structure of class names programmatically added to controls and containers to reflect the state of the mixer.
Most commonly, class names are added to controls by MixItUp to indicate that
the control is active so that it can be styled accordingly - 'mixitup-control-active'
by default.
Using a “BEM” like structure, each classname is broken into the three parts:
a block namespace ('mixitup'
), an element name (e.g. 'control'
), and an optional modifier
name (e.g. 'active'
) reflecting the state of the element.
By default, each part of the classname is concatenated together using single hyphens as delineators, but this can be easily customised to match the naming convention and style of your project.
block
Type | Default |
---|---|
string | 'mixitup' |
The “block” portion, or top-level namespace added to the start of any class names created by MixItUp.
elementContainer
Type | Default |
---|---|
string | 'container' |
The “element” portion of the class name added to container.
elementFilter
Type | Default |
---|---|
string | 'control' |
The “element” portion of the class name added to filter controls.
By default, all filter, sort, multimix and toggle controls take the same element value of 'control'
, but
each type’s element value can be individually overwritten to match the unique classNames of your controls as needed.
elementSort
Type | Default |
---|---|
string | 'control' |
The “element” portion of the class name added to sort controls.
By default, all filter, sort, multimix and toggle controls take the same element value of 'control'
, but
each type’s element value can be individually overwritten to match the unique classNames of your controls as needed.
elementMultimix
Type | Default |
---|---|
string | 'control' |
The “element” portion of the class name added to multimix controls.
By default, all filter, sort, multimix and toggle controls take the same element value of 'control'
, but
each type’s element value can be individually overwritten to match the unique classNames of your controls as needed.
elementToggle
Type | Default |
---|---|
string | 'control' |
The “element” portion of the class name added to toggle controls.
By default, all filter, sort, multimix and toggle controls take the same element value of 'control'
, but
each type’s element value can be individually overwritten to match the unique classNames of your controls as needed.
modifierActive
Type | Default |
---|---|
string | 'active' |
The “modifier” portion of the class name added to active controls.
modifierDisabled
Type | Default |
---|---|
string | 'disabled' |
The “modifier” portion of the class name added to disabled controls.
modifierFailed
Type | Default |
---|---|
string | 'failed' |
The “modifier” portion of the class name added to the container when in a “failed” state.
delineatorElement
Type | Default |
---|---|
string | '-' |
The delineator used between the “block” and “element” portions of any class name added by MixItUp.
If the block portion is ommited by setting it to an empty string, no delineator will be added.
delineatorModifier
Type | Default |
---|---|
string | '-' |
The delineator used between the “element” and “modifier” portions of any class name added by MixItUp.
If the element portion is ommited by setting it to an empty string, no delineator will be added.
mixitup.Config.data
A group of properties relating to MixItUp’s dataset API.
uidKey
Type | Default |
---|---|
string | '' |
A string specifying the name of the key containing your data model’s unique identifier (UID). To use the dataset API, a UID key must be specified and be present and unique on all objects in the dataset you provide to MixItUp.
For example, if your dataset is made up of MongoDB documents, the UID
key would be 'id'
or '_id'
.
dirtyCheck
Type | Default |
---|---|
boolean | false |
A boolean dictating whether or not MixItUp should “dirty check” each object in
your dataset for changes whenever .dataset()
is called, and re-render any targets
for which a change is found.
Depending on the complexity of your data model, dirty checking can be expensive and is therefore disabled by default.
NB: For changes to be detected, a new immutable instance of the edited model must be
provided to mixitup, rather than manipulating properties on the existing instance.
If your changes are a result of a DB write and read, you will most likely be calling
.dataset()
with a clean set of objects each time, so this will not be an issue.
mixitup.Config.debug
A group of properties allowing the toggling of various debug features.
enable
Type | Default |
---|---|
boolean | false |
A boolean dictating whether or not the mixer instance returned by the
mixitup()
factory function should expose private properties and methods.
By default, mixer instances only expose their public API, but enabling debug mode will give you access to various mixer internals which may aid in debugging, or the authoring of extensions.
showWarnings
Type | Default |
---|---|
boolean | true |
A boolean dictating whether or not warnings should be shown when various common gotchas occur.
Warnings are intended to provide insights during development when something occurs that is not a fatal, but may indicate an issue with your integration, and are therefore turned on by default. However, you may wish to disable them in production.
mixitup.Config.layout
A group of properties relating to the layout of the container.
allowNestedTargets
Type | Default |
---|---|
boolean | true |
A boolean dictating whether or not mixitup should query all descendants of the container for targets, or only immediate children.
By default, mixitup will query all descendants matching the
selectors.target
selector when indexing targets upon instantiation.
This allows for targets to be nested inside a sub-container which is
useful when ring-fencing targets from locally scoped controls in your
markup (see controls.scope
).
However, if you are building a more complex UI requiring the nesting
of mixers within mixers, you will most likely want to limit targets to
immediate children of the container by setting this property to false
.
containerClassName
Type | Default |
---|---|
string | '' |
A string specifying an optional class name to apply to the container when in its default state.
By changing this class name or adding a class name to the container via the
.changeLayout()
API method, the CSS layout of the container can be changed,
and MixItUp will attemp to gracefully animate the container and its targets
between states.
siblingBefore
Type | Default |
---|---|
HTMLElement | null |
A reference to a non-target sibling element after which to insert targets when there are no targets in the container.
siblingAfter
Type | Default |
---|---|
HTMLElement | null |
A reference to a non-target sibling element before which to insert targets when there are no targets in the container.
mixitup.Config.load
A group of properties defining the initial state of the mixer on load (instantiation).
filter
Type | Default |
---|---|
string | 'all' |
A string defining any filtering to be statically applied to the mixer on load.
As per the .filter()
API, this can be any valid selector string, or the
values 'all'
or 'none'
.
sort
Type | Default |
---|---|
string | 'default:asc' |
A string defining any sorting to be statically applied to the mixer on load.
As per the .sort()
API, this should be a valid “sort string” made up of
an attribute to sort by (or 'default'
) followed by an optional sorting
order, or the value 'random'
;
dataset
Type | Default |
---|---|
Array.<object> | null |
An array of objects representing the underlying data of any pre-rendered targets,
when using the .dataset()
API.
NB: If targets are pre-rendered when the mixer is instantiated, this must be set.
mixitup.Config.selectors
A group of properties defining the selectors used to query elements within a mixitup container.
target
Type | Default |
---|---|
string | '.mix' |
A selector string used to query and index target elements within the container.
By default, the class selector '.mix'
is used, but this can be changed to an
attribute or element selector to match the style of your project.
control
Type | Default |
---|---|
string | '' |
A optional selector string used to add further specificity to the querying of control elements,
in addition to their mandatory data attribute (e.g. data-filter
, data-toggle
, data-sort
).
This can be used if other elements in your document must contain the above attributes
(e.g. for use in third-party scripts), and would otherwise interfere with MixItUp. Adding
an additional control
selector of your choice allows MixItUp to restrict event handling
to only those elements matching the defined selector.
mixitup.Config.render
A group of optional render functions for creating and updating elements.
All render functions receive a data object, and should return a valid HTML string.
target
Type | Default |
---|---|
function | 'null' |
A function returning an HTML string representing a target element, or a reference to a single DOM element.
The function is invoked as part of the .dataset()
API, whenever a new item is added
to the dataset, or an item in the dataset changes (if dataset.dirtyCheck
is enabled).
The function receives the relevant dataset item as its first parameter.