Carousel
Materialize is a modern responsive CSS framework based on Material Design by Google.
Note: This is also touch compatible! Try swiping with your finger to scroll through the carousel.
Copied!
content_copy
Initialization
Copied!
content_copy
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.carousel');
var instances = M.Carousel.init(elems, {
// specify options here
});
});
Options
Name | Type | Default | Description |
---|---|---|---|
duration | Number | 200 | Transition duration in milliseconds. |
dist | Number | -100 | Perspective zoom. If 0, all items are the same size. |
shift | Number | 0 | Set the spacing of the center item. |
padding | Number | 0 | Set the padding between non center items. |
numVisible | Number | 5 | Set the number of visible items. |
fullWidth | Boolean | false | Make the carousel a full width slider like the second example. |
indicators | Boolean | false | Set to true to show indicators. |
noWrap | Boolean | false | Don't wrap around and cycle through items. |
onCycleTo | Function | null | Callback for when a new slide is cycled to. |
Methods
All the methods are called on the plugin instance. You can get the plugin instance like this:
Copied! content_copyvar instance = M.Carousel.getInstance(elem);
.next();
Move carousel to next slide or go forward a given amount of slides.
Arguments
Integer (optional): How many times the carousel slides.
instance.next();
instance.next(3); // Move next n times.
.prev();
Move carousel to previous slide or go back a given amount of slides.
Arguments
Integer (optional): How many times the carousel slides.
instance.prev();
instance.prev(3); // Move previous n times.
.set();
Move carousel to nth slide
Arguments
Integer: Index of slide.
instance.set();
instance.set(3); // Set to nth slide.
.destroy();
Destroy plugin instance and teardown
instance.destroy();
Properties
Name | Type | Description |
---|---|---|
el | Element | The DOM element the plugin was initialized with. |
options | Object | The options the instance was initialized with. |
pressed | Boolean | If the carousel is being clicked or tapped. |
dragged | Boolean | If the carousel is currently being dragged. |
center | Number | The index of the center carousel item. |
Full Width Slider
Note: This is also touch compatible! Try swiping with your finger to scroll through the carousel.
Copied!
content_copy
Copied!
content_copy
var instance = M.Carousel.init({
fullWidth: true
});
Special Options
Note: This is also touch compatible! Try swiping with your finger to scroll through the carousel.
Copied!
content_copy
Copied!
content_copy
var instance = M.Carousel.init({
fullWidth: true,
indicators: true
});