Extras
- Extra demos
- Custom navigation UI
- Module loaders
- Webpack
- Browserify
- RequireJS
- Browser support
- Upgrading from v1
- Breaking changes
- Compatible changes
- New features
- Issues
- Reduced test cases
- Submitting issues
- Feature requests
Extra demos
- Image carousel with fancy selected style
- Setting image caption or with vanilla JS
- Select cell on staticClick or with vanilla JS
- Vertical scrollable navigation on the side
- Set initial focus on Flickity carousel or with vanilla JS, so that carousel can be keyboard navigated on initial page load
- Previous & next buttons in top right corner
-
Adding
is-previous
andis-next
cell classes or withwrapAround
- Fade in carousel for no Flash Of Unstyled Content (FOUC) or with vanilla JS
- Disabling & enabling dragging or with vanilla JS
- Set options at media queries
- Detecting user-triggered select events, excluding autoPlay and resize-triggered
- Equal cell heights hack
- Set custom autoPlay intervals per slide
- Current slide / total number of slides CSS only
Custom navigation UI
With the Flickity API, you can build custom carousel navigation UI.
// init Flickity
var $carousel = $('.carousel').flickity({
prevNextButtons: false,
pageDots: false
});
// Flickity instance
var flkty = $carousel.data('flickity');
// elements
var $cellButtonGroup = $('.button-group--cells');
var $cellButtons = $cellButtonGroup.find('.button');
// update selected cellButtons
$carousel.on( 'select.flickity', function() {
$cellButtons.filter('.is-selected')
.removeClass('is-selected');
$cellButtons.eq( flkty.selectedIndex )
.addClass('is-selected');
});
// select cell on button click
$cellButtonGroup.on( 'click', '.button', function() {
var index = $(this).index();
$carousel.flickity( 'select', index );
});
// previous
$('.button--previous').on( 'click', function() {
$carousel.flickity('previous');
});
// next
$('.button--next').on( 'click', function() {
$carousel.flickity('next');
});
Edit this demo or vanilla JS demo on CodePen
Module loaders
Webpack
Install Flickity with npm.
npm install flickity
You can then require('flickity')
.
// main.js
var Flickity = require('flickity');
var flkty = new Flickity( '.carousel', {
// options...
});
Run webpack
.
webpack main.js bundle.js
Install and require add-on features for imagesLoaded
, asNavFor
, fullscreen
, bgLazyLoad
, and hash
.
npm install flickity-imagesloaded
npm install flickity-fullscreen
var Flickity = require('flickity');
require('flickity-imagesloaded');
require('flickity-fullscreen');
// now use imagesLoaded and fullscreen
var flkty = new Flickity( '.carousel', {
imagesLoaded: true,
fullscreen: true,
});
To use Flickity as a jQuery plugin with Webpack, you need to call jQuery Bridget and Flickity.setJQuery()
.
npm install jquery-bridget
var $ = require('jquery');
var jQueryBridget = require('jquery-bridget');
var Flickity = require('flickity');
// make Flickity a jQuery plugin
Flickity.setJQuery( $ );
jQueryBridget( 'flickity', Flickity, $ );
// now you can use $().flickity()
var $carousel = $('.carousel').flickity({...});
Browserify
Follow Webpack instructions. Then run browserify
.
browserify main.js -o bundle.js
RequireJS
Flickity supports RequireJS.
You can require flickity.pkgd.js
.
requirejs( [
'path/to/flickity.pkgd.js',
], function( Flickity ) {
var flkty = new Flickity( '.carousel', {...});
});
Install and require add-on features for imagesLoaded
, asNavFor
, fullscreen
, bgLazyLoad
, and hash
.
requirejs( [
'path/to/flickity.pkgd.js',
'path/to/flickity-imagesloaded/flickity-imagesloaded.js',
'path/to/flickity-fullscreen/fullscreen.js',
], function( Flickity ) {
var flkty = new Flickity( '.carousel', {
imagesLoaded: true,
fullscreen: true,
});
});
To use Flickity as a jQuery plugin with RequireJS and flickity.pkgd.js
, you need to call jQuery Bridget.
// require the require function
requirejs( [ 'require', 'jquery', 'path/to/flickity.pkgd.js' ],
function( require, $, Flickity ) {
// require jquery-bridget, it's included in flickity.pkgd.js
require( [ 'jquery-bridget/jquery-bridget' ],
function( jQueryBridget ) {
// make Flickity a jQuery plugin
jQueryBridget( 'flickity', Flickity, $ );
// now you can use $().flickity()
var $carousel = $('.carousel').flickity({...});
}
);
});
Or, you can manage dependencies with npm or Bower. Set baseUrl
to the packages folder and set a config path for all your application code.
requirejs.config({
baseUrl: 'node_modules/',
paths: {
app: '../'
}
});
requirejs( [
'flickity/js/index',
'app/my-component.js'
], function( Flickity, myComp ) {
var flkty = new Flickity( '.carousel', {...});
});
To use Flickity as a jQuery plugin with RequireJS and a package manager, you need to install and call jQuery Bridget.
requirejs.config({
baseUrl: 'node_modules/',
paths: {
jquery: 'jquery/jquery'
}
});
requirejs( [
'jquery',
'flickity/js/index',
'jquery-bridget/jquery-bridget'
],
function( $, Flickity ) {
// make Flickity a jQuery plugin
$.bridget( 'flickity', Flickity, $ );
// now you can use $().flickity()
var $carousel = $('.carousel').flickity({...});
});
Browser support
Flickity v2.1 supports Chrome 33+, Safari 9+ (mobile & desktop), IE11+, Edge 12+, and Firefox 23+.
For IE8+ and Android 2.3+ support, try Flickity v1.
Upgrading from v1
Flickity v2 dropped browser support for IE8, IE9, and Android 2.3. Nearly all options, methods, and code for Flickity v1 is backwards compatibile with Flickity v2.
Breaking changes
-
jQuery events are namespaced with
.flickity
.// v1, will not work with v2 $carousel.on( 'staticClick', function() {...}) // v2, add .flickity namespace $carousel.on( 'staticClick.flickity', function() {...})
jquery-bridget/jquery.bridget
path renamed tojquery-bridget/jquery-bridget
Compatible changes
select
event added in place ofcellSelect
.cellSelect
event will continue to work.- HTML initialization can be done with
data-flickity
. Flickity v2 is backwards compatible with previous code:js-flickity
class anddata-flickity-options
attribute. - IE8 helper dependencies removed: eventie, get-style-property, doc-ready
New features
- groupCells - group cells together as individual slides
- adaptiveHeight - change carousel height to selected cell
- bgLazyLoad - lazyload background images
- scroll event - do cool stuff like progress bars and parallax effects
- dragThreshold - add more wiggle room for touch vertical scrolling
Issues
Reduced test cases
Creating a reduced test case is the best way to debug problems and report issues. Read CSS Tricks on why they’re so great.
Create a reduced test case for Flickity by forking any one of the CodePen demos from these docs.
- A reduced test case clearly demonstrates the bug or issue.
- It contains the bare minimum HTML, CSS, and JavaScript required to demonstrate the bug.
- A link to your production site is not a reduced test case.
Creating a reduced test case is the best way to get your issue addressed. They help you point out the problem. They help us debug the problem. They help others understand the problem.
Submitting issues
Report issues on GitHub. Make sure to include a reduced test case. Without a reduced test case, your issue may be closed.
Feature requests
Help us select new features by looking over requested features on the GitHub issue tracker and adding your 👍 reaction to features you’d like to see added.