<!-- Slider main container -->
<div class="swiper">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
...
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<!-- If we need scrollbar -->
<div class="swiper-scrollbar"></div>
</div>
Swiper package contains different sets of CSS, Less and SCSS styles:
CSS styles for bundle version:
swiper-bundle.css
- all Swiper styles including all modules styles (like Navigation, Pagination, etc.)swiper-bundle.min.css
- same as previous but minifiedCSS styles for bundle version (package imports):
swiper/css
- all Swiper styles including all modules styles (like Navigation, Pagination, etc.)swiper/css/bundle
- same as previous but minifiedCSS styles for core version and modules (package imports):
swiper/css
- only core Swiper stylesswiper/css/a11y
- styles required for A11y moduleswiper/css/autoplay
- styles required for Autoplay moduleswiper/css/controller
- styles required for Controller moduleswiper/css/effect-cards
- styles required for Cards Effect moduleswiper/css/effect-coverflow
- styles required for Coverflow Effect moduleswiper/css/effect-creative
- styles required for Creative Effect moduleswiper/css/effect-cube
- styles required for Cube Effect moduleswiper/css/effect-fade
- styles required for Fade Effect moduleswiper/css/effect-flip
- styles required for Flip Effect moduleswiper/css/free-mode
- styles required for Free Mode moduleswiper/css/grid
- styles required for Grid moduleswiper/css/hash-navigation
- styles required for Hash Navigation moduleswiper/css/history
- styles required for History moduleswiper/css/keyboard
- styles required for Keyboard moduleswiper/css/manipulation
- styles required for Manipulation moduleswiper/css/mousewheel
- styles required for Mousewheel moduleswiper/css/navigation
- styles required for Navigation moduleswiper/css/pagination
- styles required for Pagination moduleswiper/css/parallax
- styles required for Parallax moduleswiper/css/scrollbar
- styles required for Scrollbar moduleswiper/css/thumbs
- styles required for Thumbs moduleswiper/css/virtual
- styles required for Virtual moduleswiper/css/zoom
- styles required for Zoom moduleLess styles are separate styles for core version and modules (package imports):
swiper/less
- only core Swiper stylesswiper/less/bundle
- all Swiper styles including all modules styles (like Navigation, Pagination, etc.)swiper/less/a11y
- styles required for A11y moduleswiper/less/autoplay
- styles required for Autoplay moduleswiper/less/controller
- styles required for Controller moduleswiper/less/effect-cards
- styles required for Cards Effect moduleswiper/less/effect-coverflow
- styles required for Coverflow Effect moduleswiper/less/effect-creative
- styles required for Creative Effect moduleswiper/less/effect-cube
- styles required for Cube Effect moduleswiper/less/effect-fade
- styles required for Fade Effect moduleswiper/less/effect-flip
- styles required for Flip Effect moduleswiper/less/free-mode
- styles required for Free Mode moduleswiper/less/grid
- styles required for Grid moduleswiper/less/hash-navigation
- styles required for Hash Navigation moduleswiper/less/history
- styles required for History moduleswiper/less/keyboard
- styles required for Keyboard moduleswiper/less/manipulation
- styles required for Manipulation moduleswiper/less/mousewheel
- styles required for Mousewheel moduleswiper/less/navigation
- styles required for Navigation moduleswiper/less/pagination
- styles required for Pagination moduleswiper/less/parallax
- styles required for Parallax moduleswiper/less/scrollbar
- styles required for Scrollbar moduleswiper/less/thumbs
- styles required for Thumbs moduleswiper/less/virtual
- styles required for Virtual moduleswiper/less/zoom
- styles required for Zoom moduleSCSS styles are also separate styles for core version and modules (package imports):
swiper/scss
- only core Swiper stylesswiper/scss/bundle
- all Swiper styles including all modules styles (like Navigation, Pagination, etc.)swiper/scss/a11y
- styles required for A11y moduleswiper/scss/autoplay
- styles required for Autoplay moduleswiper/scss/controller
- styles required for Controller moduleswiper/scss/effect-cards
- styles required for Cards Effect moduleswiper/scss/effect-coverflow
- styles required for Coverflow Effect moduleswiper/scss/effect-creative
- styles required for Creative Effect moduleswiper/scss/effect-cube
- styles required for Cube Effect moduleswiper/scss/effect-fade
- styles required for Fade Effect moduleswiper/scss/effect-flip
- styles required for Flip Effect moduleswiper/scss/free-mode
- styles required for Free Mode moduleswiper/scss/grid
- styles required for Grid moduleswiper/scss/hash-navigation
- styles required for Hash Navigation moduleswiper/scss/history
- styles required for History moduleswiper/scss/keyboard
- styles required for Keyboard moduleswiper/scss/manipulation
- styles required for Manipulation moduleswiper/scss/mousewheel
- styles required for Mousewheel moduleswiper/scss/navigation
- styles required for Navigation moduleswiper/scss/pagination
- styles required for Pagination moduleswiper/scss/parallax
- styles required for Parallax moduleswiper/scss/scrollbar
- styles required for Scrollbar moduleswiper/scss/thumbs
- styles required for Thumbs moduleswiper/scss/virtual
- styles required for Virtual moduleswiper/scss/zoom
- styles required for Zoom moduleNow, when we have Swiper's HTML, we need to initialize it using the following function:
new Swiper(swiperContainer, parameters)- initialize swiper with options
For example:
const swiper = new Swiper('.swiper', {
speed: 400,
spaceBetween: 100,
});
After you initialize Swiper it is possible to access to Swiper's instance on its HTMLElement. It is swiper
property of Swiper's HTML container element:
const swiper = document.querySelector('.swiper').swiper;
// Now you can use all slider methods like
swiper.slideNext();
Let's look on list of all available parameters:
Name | Type | Default | Description |
---|---|---|---|
allowSlideNext | boolean | true | Set to |
allowSlidePrev | boolean | true | Set to |
allowTouchMove | boolean | true | If |
autoHeight | boolean | false | Set to |
breakpoints | object | Allows to set different parameter for different responsive breakpoints (screen sizes). Not all parameters can be changed in breakpoints, only those which do not require different layout and logic, like
| |
breakpointsBase | string | 'window' | Base for breakpoints (beta). Can be
|
centerInsufficientSlides | boolean | false | When enabled it center slides if the amount of slides less than |
centeredSlides | boolean | false | If |
centeredSlidesBounds | boolean | false | If |
containerModifierClass | string | 'swiper-' | The beginning of the modifier CSS class that can be added to swiper container depending on different parameters |
createElements | boolean | false | When enabled Swiper will automatically wrap slides with swiper-wrapper element, and will create required elements for navigation, pagination and scrollbar they are enabled (with their respective params object or with boolean |
cssMode | boolean | false | When enabled it will use modern CSS Scroll Snap API. It doesn't support all of Swiper's features, but potentially should bring a much better performance in simple configurations. This is what is not supported when it is enabled:
In case if you use it with other effects, especially 3D effects, it is required to wrap slide's content with
|
direction | 'horizontal' | 'vertical' | 'horizontal' | Can be |
edgeSwipeDetection | string | boolean | false | Enable to release Swiper events for swipe-back work in app. If set to |
edgeSwipeThreshold | number | 20 | Area (in px) from left edge of the screen to release touch events for swipe-back in app |
effect | string | 'slide' | Transition effect. Can be |
enabled | boolean | true | Whether Swiper initially enabled. When Swiper is disabled, it will hide all navigation elements and won't respond to any events and interactions |
focusableElements | string | 'input, select, option, textarea, button, video, label' | CSS selector for focusable elements. Swiping will be disabled on such elements if they are "focused" |
followFinger | boolean | true | If disabled, then slider will be animated only when you release it, it will not move while you hold your finger on it |
grabCursor | boolean | false | This option may a little improve desktop usability. If |
height | null | number | null | Swiper height (in px). Parameter allows to force Swiper height. Useful only if you initialize Swiper when it is hidden and in SSR and Test environments for correct Swiper initialization
|
init | boolean | true | Whether Swiper should be initialised automatically when you create an instance. If disabled, then you need to init it manually by calling |
initialSlide | number | 0 | Index number of initial slide. |
injectStyles | string[] | Inject text styles to the shadow DOM. Only for usage with Swiper Element | |
injectStylesUrls | string[] | Inject styles | |
lazyPreloadPrevNext | number | 0 | Number of next and previous slides to preload. Only applicable if using lazy loading. |
lazyPreloaderClass | string | 'swiper-lazy-preloader' | CSS class name of lazy preloader |
longSwipes | boolean | true | Set to |
longSwipesMs | number | 300 | Minimal duration (in ms) to trigger swipe to next/previous slide during long swipes |
longSwipesRatio | number | 0.5 | Ratio to trigger swipe to next/previous slide during long swipes |
loop | boolean | false | Set to Because of nature of how the loop mode works (it will rearrange slides), total number of slides must be >= slidesPerView * 2 |
loopPreventsSliding | boolean | true | If enabled then slideNext/Prev will do nothing while slider is animating in loop mode |
loopedSlides | null | number | null | Defines how many slides before end/beginning it should rearrange (loop) slides. If not specified, defaults to |
maxBackfaceHiddenSlides | number | 10 | If total number of slides less than specified here value, then Swiper will enable
|
modules | SwiperModule[] | Array with Swiper modules
| |
nested | boolean | false | Set to |
noSwiping | boolean | true | Enable/disable swiping on elements matched to class specified in |
noSwipingClass | string | 'swiper-no-swiping' | Specify |
noSwipingSelector | string | Can be used instead of | |
normalizeSlideIndex | boolean | true | Normalize slide index. |
observeParents | boolean | false | Set to |
observeSlideChildren | boolean | false | Set to |
observer | boolean | false | Set to |
on | object | Register event handlers | |
onAny | function(handler) | Add event listener that will be fired on all events
| |
oneWayMovement | boolean | false | When enabled, will swipe slides only forward (one-way) regardless of swipe direction |
passiveListeners | boolean | true | Passive event listeners will be used by default where possible to improve scrolling performance on mobile devices. But if you need to use |
preventClicks | boolean | true | Set to |
preventClicksPropagation | boolean | true | Set to |
preventInteractionOnTransition | boolean | false | When enabled it won't allow to change slides by swiping or navigation/pagination buttons during transition |
resistance | boolean | true | Set to |
resistanceRatio | number | 0.85 | This option allows you to control resistance ratio |
resizeObserver | boolean | true | When enabled it will use ResizeObserver (if supported by browser) on swiper container to detect container resize (instead of watching for window resize) |
rewind | boolean | false | Set to
|
roundLengths | boolean | false | Set to |
runCallbacksOnInit | boolean | true | Fire Transition/SlideChange/Start/End events on swiper initialization. Such events will be fired on initialization in case of your initialSlide is not 0, or you use loop mode |
setWrapperSize | boolean | false | Enabled this option and plugin will set width/height on swiper wrapper equal to total size of all slides. Mostly should be used as compatibility fallback option for browser that don't support flexbox layout well |
shortSwipes | boolean | true | Set to |
simulateTouch | boolean | true | If |
slideActiveClass | string | 'swiper-slide-active' | CSS class name of currently active slide
|
slideClass | string | 'swiper-slide' | CSS class name of slide
|
slideNextClass | string | 'swiper-slide-next' | CSS class name of slide which is right after currently active slide
|
slidePrevClass | string | 'swiper-slide-prev' | CSS class name of slide which is right before currently active slide
|
slideToClickedSlide | boolean | false | Set to |
slideVisibleClass | string | 'swiper-slide-visible' | CSS class name of currently visible slide
|
slidesOffsetAfter | number | 0 | Add (in px) additional slide offset in the end of the container (after all slides) |
slidesOffsetBefore | number | 0 | Add (in px) additional slide offset in the beginning of the container (before all slides) |
slidesPerGroup | number | 1 | Set numbers of slides to define and enable group sliding. Useful to use with slidesPerView > 1 |
slidesPerGroupAuto | boolean | false | This param intended to be used only with |
slidesPerGroupSkip | number | 0 | The parameter works in the following way: If If |
slidesPerView | number | 'auto' | 1 | Number of slides per view (slides visible at the same time on slider's container).
|
spaceBetween | string | number | 0 | Distance between slides in px.
|
speed | number | 300 | Duration of transition between slides (in ms) |
swipeHandler | null | HTMLElement | CSSSelector | null | String with CSS selector or HTML element of the container with pagination that will work as only available handler for swiping |
threshold | number | 5 | Threshold value in px. If "touch distance" will be lower than this value then swiper will not move |
touchAngle | number | 45 | Allowable angle (in degrees) to trigger touch move |
touchEventsTarget | 'container' | 'wrapper' | 'wrapper' | Target element to listen touch events on. Can be |
touchMoveStopPropagation | boolean | false | If enabled, then propagation of "touchmove" will be stopped |
touchRatio | number | 1 | Touch ratio |
touchReleaseOnEdges | boolean | false | Enable to release touch events on slider edge position (beginning, end) to allow for further page scrolling |
touchStartForcePreventDefault | boolean | false | Force to always prevent default for |
touchStartPreventDefault | boolean | true | If disabled, |
uniqueNavElements | boolean | true | If enabled (by default) and navigation elements' parameters passed as a string (like |
updateOnWindowResize | boolean | true | Swiper will recalculate slides position on window resize (orientationchange) |
url | null | string | null | Required for active slide detection when rendered on server-side and enabled history |
userAgent | null | string | null | userAgent string. Required for browser/device detection when rendered on server-side |
virtualTranslate | boolean | false | Enabled this option and swiper will be operated as usual except it will not move, real translate values on wrapper will not be set. Useful when you may need to create custom slide transition |
watchOverflow | boolean | true | When enabled Swiper will be disabled and hide navigation buttons on case there are not enough slides for sliding. |
watchSlidesProgress | boolean | false | Enable this feature to calculate each slides progress and visibility (slides in viewport will have additional visible class) |
width | null | number | null | Swiper width (in px). Parameter allows to force Swiper width. Useful only if you initialize Swiper when it is hidden and in SSR and Test environments for correct Swiper initialization
|
wrapperClass | string | 'swiper-wrapper' | CSS class name of slides' wrapper
|
After we initialize Slider we have its initialized instance in variable (like swiper
variable in example above) with helpful methods and properties:
Properties | ||
---|---|---|
swiper.activeIndex | number | Index number of currently active slide
|
swiper.allowSlideNext | boolean | Disable / enable ability to slide to the next slides by assigning |
swiper.allowSlidePrev | boolean | Disable / enable ability to slide to the previous slides by assigning |
swiper.allowTouchMove | boolean | Disable / enable ability move slider by grabbing it with mouse or by touching it with finger (on touch screens) by assigning |
swiper.animating | boolean |
|
swiper.clickedIndex | number | Index number of last clicked slide |
swiper.clickedSlide | HTMLElement | Link to last clicked slide (HTMLElement) |
swiper.defaults | SwiperOptions | Swiper default options |
swiper.el | HTMLElement | Slider container HTML element |
swiper.extendedDefaults | SwiperOptions | Object with global Swiper extended options |
swiper.height | number | Height of container |
swiper.isBeginning | boolean |
|
swiper.isEnd | boolean |
|
swiper.isLocked | boolean |
|
swiper.originalParams | SwiperOptions | Object with original initialization parameters |
swiper.params | SwiperOptions | Object with passed initialization parameters |
swiper.previousIndex | number | Index number of previously active slide |
swiper.progress | number | Current progress of wrapper translate (from 0 to 1) |
swiper.realIndex | number | Index number of currently active slide considering rearranged slides in loop mode |
swiper.slides | HTMLElement[] | Array of slides HTML elements. To get specific slide HTMLElement use |
swiper.snapGrid | number[] | Slides snap grid |
swiper.snapIndex | number | Index number of current snap in |
swiper.swipeDirection | 'prev' | 'next' | Direction of sliding |
swiper.touches | object | Object with the following touch event properties:
|
swiper.translate | number | Current value of wrapper translate |
swiper.width | number | Width of container |
swiper.wrapperEl | HTMLElement | Wrapper HTML element |
Methods | ||
swiper.attachEvents() | Attach all events listeners again | |
swiper.changeDirection(direction, needUpdate) | Changes slider direction from horizontal to vertical and back.
| |
swiper.changeLanguageDirection(direction) | Changes slider language
| |
swiper.destroy(deleteInstance, cleanStyles) | Destroy slider instance and detach all events listeners
| |
swiper.detachEvents() | Detach all events listeners | |
swiper.disable() | Disable Swiper (if it was enabled). When Swiper is disabled, it will hide all navigation elements and won't respond to any events and interactions | |
swiper.emit(event, args) | Fire event on instance | |
swiper.enable() | Enable Swiper (if it was disabled) | |
swiper.extendDefaults(options) | Extend global Swiper defaults | |
swiper.getTranslate() | Get current value of swiper wrapper css3 transform translate | |
swiper.init(el) | Initialize slider | |
swiper.off(event, handler) | Remove event handler | |
swiper.offAny(handler) | Remove event listener that will be fired on all events | |
swiper.on(event, handler) | Add event handler | |
swiper.onAny(handler) | Add event listener that will be fired on all events | |
swiper.once(event, handler) | Add event handler that will be removed after it was fired | |
swiper.setGrabCursor() | Set grab cursor | |
swiper.setProgress(progress, speed) | Set Swiper translate progress (from 0 to 1). Where 0 - its initial position (offset) on first slide, and 1 - its maximum position (offset) on last slide
| |
swiper.setTranslate(translate) | Set custom css3 transform's translate value for swiper wrapper | |
swiper.slideNext(speed, runCallbacks) | Run transition to next slide.
| |
swiper.slidePrev(speed, runCallbacks) | Run transition to previous slide.
| |
swiper.slideReset(speed, runCallbacks) | Reset swiper position to currently active slide for the duration equal to 'speed' parameter.
| |
swiper.slideTo(index, speed, runCallbacks) | Run transition to the slide with index number equal to 'index' parameter for the duration equal to 'speed' parameter.
| |
swiper.slideToClosest(speed, runCallbacks) | Reset swiper position to closest slide/snap point for the duration equal to 'speed' parameter.
| |
swiper.slideToLoop(index, speed, runCallbacks) | Does the same as .slideTo but for the case when used with enabled loop. So this method will slide to slides with realIndex matching to passed index
| |
swiper.translateTo(translate, speed, runCallbacks, translateBounds) | Animate custom css3 transform's translate value for swiper wrapper
| |
swiper.unsetGrabCursor() | Unset grab cursor | |
swiper.update() | You should call it after you add/remove slides manually, or after you hide/show it, or do any custom DOM modifications with Swiper This method also includes subcall of the following methods which you can use separately: | |
swiper.updateAutoHeight(speed) | Force swiper to update its height (when autoHeight enabled) for the duration equal to 'speed' parameter
| |
swiper.updateProgress() | recalculate swiper progress | |
swiper.updateSize() | recalculate size of swiper container | |
swiper.updateSlides() | recalculate number of slides and their offsets. Useful after you add/remove slides with JavaScript | |
swiper.updateSlidesClasses() | update active/prev/next classes on slides and bullets | |
swiper.use(modules) | Installs modules on Swiper in runtime. |
Swiper comes with a bunch of useful events you can listen. Events can be assigned in two ways:
Using on
parameter on swiper initialization:
const swiper = new Swiper('.swiper', {
// ...
on: {
init: function () {
console.log('swiper initialized');
},
},
});
Using on
method after swiper initialization.
const swiper = new Swiper('.swiper', {
// ...
});
swiper.on('slideChange', function () {
console.log('slide changed');
});
this
keyword within event handler always points to Swiper instanceName | Arguments | Description |
---|---|---|
activeIndexChange | (swiper) | Event will fired on active index change |
afterInit | (swiper) | Event will fired right after initialization |
beforeDestroy | (swiper) | Event will be fired right before Swiper destroyed |
beforeInit | (swiper) | Event will fired right before initialization |
beforeLoopFix | (swiper) | Event will be fired right before "loop fix" |
beforeResize | (swiper) | Event will fired before resize handler |
beforeSlideChangeStart | (swiper) | Event will fired before slide change transition start |
beforeTransitionStart | (swiper, speed, internal) | Event will fired before transition start |
breakpoint | (swiper, breakpointParams) | Event will be fired on breakpoint change |
changeDirection | (swiper) | Event will fired on direction change |
click | (swiper, event) | Event will be fired when user click/tap on Swiper. Receives |
destroy | (swiper) | Event will be fired on swiper destroy |
doubleClick | (swiper, event) | Event will be fired when user double click/tap on Swiper |
doubleTap | (swiper, event) | Event will be fired when user double tap on Swiper's container. Receives |
fromEdge | (swiper) | Event will be fired when Swiper goes from beginning or end position |
init | (swiper) | Fired right after Swiper initialization.
|
lock | (swiper) | Event will be fired when swiper is locked (when |
loopFix | (swiper) | Event will be fired after "loop fix" |
momentumBounce | (swiper) | Event will be fired on momentum bounce |
observerUpdate | (swiper) | Event will be fired if observer is enabled and it detects DOM mutations |
orientationchange | (swiper) | Event will be fired on orientation change (e.g. landscape -> portrait) |
progress | (swiper, progress) | Event will be fired when Swiper progress is changed, as an arguments it receives progress that is always from 0 to 1 |
reachBeginning | (swiper) | Event will be fired when Swiper reach its beginning (initial position) |
reachEnd | (swiper) | Event will be fired when Swiper reach last slide |
realIndexChange | (swiper) | Event will fired on real index change |
resize | (swiper) | Event will be fired on window resize right before swiper's onresize manipulation |
setTransition | (swiper, transition) | Event will be fired everytime when swiper starts animation. Receives current transition duration (in ms) as an arguments |
setTranslate | (swiper, translate) | Event will be fired when swiper's wrapper change its position. Receives current translate value as an arguments |
slideChange | (swiper) | Event will be fired when currently active slide is changed |
slideChangeTransitionEnd | (swiper) | Event will be fired after animation to other slide (next or previous). |
slideChangeTransitionStart | (swiper) | Event will be fired in the beginning of animation to other slide (next or previous). |
slideNextTransitionEnd | (swiper) | Same as "slideChangeTransitionEnd" but for "forward" direction only |
slideNextTransitionStart | (swiper) | Same as "slideChangeTransitionStart" but for "forward" direction only |
slidePrevTransitionEnd | (swiper) | Same as "slideChangeTransitionEnd" but for "backward" direction only |
slidePrevTransitionStart | (swiper) | Same as "slideChangeTransitionStart" but for "backward" direction only |
slideResetTransitionEnd | (swiper) | Event will be fired in the end of animation of resetting slide to current one |
slideResetTransitionStart | (swiper) | Event will be fired in the beginning of animation of resetting slide to current one |
sliderFirstMove | (swiper, event) | Event will be fired with first touch/drag move |
sliderMove | (swiper, event) | Event will be fired when user touch and move finger over Swiper and move it. Receives |
slidesGridLengthChange | (swiper) | Event will be fired when slides grid has changed |
slidesLengthChange | (swiper) | Event will be fired when number of slides has changed |
snapGridLengthChange | (swiper) | Event will be fired when snap grid has changed |
snapIndexChange | (swiper) | Event will fired on snap index change |
tap | (swiper, event) | Event will be fired when user click/tap on Swiper. Receives |
toEdge | (swiper) | Event will be fired when Swiper goes to beginning or end position |
touchEnd | (swiper, event) | Event will be fired when user release Swiper. Receives |
touchMove | (swiper, event) | Event will be fired when user touch and move finger over Swiper. Receives |
touchMoveOpposite | (swiper, event) | Event will be fired when user touch and move finger over Swiper in direction opposite to direction parameter. Receives |
touchStart | (swiper, event) | Event will be fired when user touch Swiper. Receives |
transitionEnd | (swiper) | Event will be fired after transition. |
transitionStart | (swiper) | Event will be fired in the beginning of transition. |
unlock | (swiper) | Event will be fired when swiper is unlocked (when |
update | (swiper) | Event will be fired after swiper.update() call |
Name | Type | Default | Description |
---|---|---|---|
navigation | boolean | NavigationOptions | Object with navigation parameters or boolean
| |
{ | |||
disabledClass | string | 'swiper-button-disabled' | CSS class name added to navigation button when it becomes disabled |
enabled | boolean | Boolean property to use with breakpoints to enable/disable navigation on certain breakpoints | |
string | 'swiper-button-hidden' | CSS class name added to navigation button when it becomes hidden | |
hideOnClick | boolean | false | Toggle navigation buttons visibility after click on Slider's container |
lockClass | string | 'swiper-button-lock' | CSS class name added to navigation button when it is disabled |
navigationDisabledClass | string | 'swiper-navigation-disabled' | CSS class name added on swiper container when navigation is disabled by breakpoint |
nextEl | null | HTMLElement | CSSSelector | null | String with CSS selector or HTML element of the element that will work like "next" button after click on it |
prevEl | null | HTMLElement | CSSSelector | null | String with CSS selector or HTML element of the element that will work like "prev" button after click on it |
} |
Properties | ||
---|---|---|
swiper.navigation.nextEl | HTMLElement | HTMLElement of "next" navigation button |
swiper.navigation.prevEl | HTMLElement | HTMLElement of "previous" navigation button |
Methods | ||
swiper.navigation.destroy() | Destroy navigation | |
swiper.navigation.init() | Initialize navigation | |
swiper.navigation.update() | Update navigation buttons state (enabled/disabled) |
Name | Arguments | Description |
---|---|---|
navigationHide | (swiper) | Event will be fired on navigation hide |
navigationNext | (swiper) | Event will be fired on navigation next button click |
navigationPrev | (swiper) | Event will be fired on navigation prev button click |
navigationShow | (swiper) | Event will be fired on navigation show |
--swiper-navigation-size: 44px;
--swiper-navigation-top-offset: 50%;
--swiper-navigation-sides-offset: 10px;
--swiper-navigation-color: var(--swiper-theme-color);
Name | Type | Default | Description |
---|---|---|---|
pagination | boolean | PaginationOptions | Object with pagination parameters or boolean
| |
{ | |||
bulletActiveClass | string | 'swiper-pagination-bullet-active' | CSS class name of currently active pagination bullet |
bulletClass | string | 'swiper-pagination-bullet' | CSS class name of single pagination bullet |
bulletElement | string | 'span' | Defines which HTML tag will be used to represent single pagination bullet. Only for |
clickable | boolean | false | If |
clickableClass | string | 'swiper-pagination-clickable' | CSS class name set to pagination when it is clickable |
currentClass | string | 'swiper-pagination-current' | CSS class name of the element with currently active index in "fraction" pagination |
dynamicBullets | boolean | false | Good to enable if you use bullets pagination with a lot of slides. So it will keep only few bullets visible at the same time. |
dynamicMainBullets | number | 1 | The number of main bullets visible when |
el | null | HTMLElement | CSSSelector | null | String with CSS selector or HTML element of the container with pagination |
enabled | boolean | Boolean property to use with breakpoints to enable/disable pagination on certain breakpoints | |
formatFractionCurrent | function(number) | format fraction pagination current number. Function receives current number, and you need to return formatted value | |
formatFractionTotal | function(number) | format fraction pagination total number. Function receives total number, and you need to return formatted value | |
string | 'swiper-pagination-hidden' | CSS class name of pagination when it becomes inactive | |
hideOnClick | boolean | true | Toggle (hide/show) pagination container visibility after click on Slider's container |
horizontalClass | string | 'swiper-pagination-horizontal' | CSS class name set to pagination in horizontal Swiper |
lockClass | string | 'swiper-pagination-lock' | CSS class name set to pagination when it is disabled |
modifierClass | string | 'swiper-pagination-' | The beginning of the modifier CSS class name that will be added to pagination depending on parameters |
paginationDisabledClass | string | 'swiper-pagination-disabled' | CSS class name added on swiper container and pagination element when pagination is disabled by breakpoint |
progressbarFillClass | string | 'swiper-pagination-progressbar-fill' | CSS class name of pagination progressbar fill element |
progressbarOpposite | boolean | false | Makes pagination progressbar opposite to Swiper's |
progressbarOppositeClass | string | 'swiper-pagination-progressbar-opposite' | CSS class name of pagination progressbar opposite |
renderBullet | function(index, className) | This parameter allows totally customize pagination bullets, you need to pass here a function that accepts
| |
renderCustom | function(swiper, current, total) | This parameter is required for
| |
renderFraction | function(currentClass, totalClass) | This parameter allows to customize "fraction" pagination html. Only for
| |
renderProgressbar | function(progressbarFillClass) | This parameter allows to customize "progress" pagination. Only for
| |
totalClass | string | 'swiper-pagination-total' | CSS class name of the element with total number of "snaps" in "fraction" pagination |
type | 'bullets' | 'fraction' | 'progressbar' | 'custom' | 'bullets' | String with type of pagination. Can be |
verticalClass | string | 'swiper-pagination-vertical' | CSS class name set to pagination in vertical Swiper |
} |
Properties | ||
---|---|---|
swiper.pagination.bullets | HTMLElement[] | Array of pagination bullets HTML elements. To get specific slide HTMLElement use |
swiper.pagination.el | HTMLElement | HTMLElement of pagination container element |
Methods | ||
swiper.pagination.destroy() | Destroy pagination | |
swiper.pagination.init() | Initialize pagination | |
swiper.pagination.render() | Render pagination layout | |
swiper.pagination.update() | Update pagination state (enabled/disabled/active) |
Name | Arguments | Description |
---|---|---|
paginationHide | (swiper) | Event will be fired on pagination hide |
paginationRender | (swiper, paginationEl) | Event will be fired after pagination rendered |
paginationShow | (swiper) | Event will be fired on pagination show |
paginationUpdate | (swiper, paginationEl) | Event will be fired when pagination updated |
--swiper-pagination-color: var(--swiper-theme-color);
--swiper-pagination-left: auto;
--swiper-pagination-right: 8px;
--swiper-pagination-bottom: 8px;
--swiper-pagination-top: auto;
--swiper-pagination-fraction-color: inherit;
--swiper-pagination-progressbar-bg-color: rgba(0, 0, 0, 0.25);
--swiper-pagination-progressbar-size: 4px;
--swiper-pagination-bullet-size: 8px;
--swiper-pagination-bullet-width: 8px;
--swiper-pagination-bullet-height: 8px;
--swiper-pagination-bullet-inactive-color: #000;
--swiper-pagination-bullet-inactive-opacity: 0.2;
--swiper-pagination-bullet-opacity: 1;
--swiper-pagination-bullet-horizontal-gap: 4px;
--swiper-pagination-bullet-vertical-gap: 6px;
Name | Type | Default | Description |
---|---|---|---|
scrollbar | boolean | ScrollbarOptions | Object with scrollbar parameters or boolean
| |
{ | |||
dragClass | string | 'swiper-scrollbar-drag' | Scrollbar draggable element CSS class |
dragSize | number | 'auto' | 'auto' | Size of scrollbar draggable element in px |
draggable | boolean | false | Set to |
el | null | HTMLElement | CSSSelector | null | String with CSS selector or HTML element of the container with scrollbar. |
enabled | boolean | Boolean property to use with breakpoints to enable/disable scrollbar on certain breakpoints | |
hide | boolean | true | Hide scrollbar automatically after user interaction |
horizontalClass | string | 'swiper-scrollbar-horizontal' | CSS class name set to scrollbar in horizontal Swiper |
lockClass | string | 'swiper-scrollbar-lock' | Scrollbar element additional CSS class when it is disabled |
scrollbarDisabledClass | string | 'swiper-scrollbar-disabled' | CSS class name added on swiper container and scrollbar element when scrollbar is disabled by breakpoint |
snapOnRelease | boolean | false | Set to |
verticalClass | string | 'swiper-scrollbar-vertical' | CSS class name set to scrollbar in vertical Swiper |
} |
Properties | ||
---|---|---|
swiper.scrollbar.dragEl | HTMLElement | HTMLElement of Scrollbar draggable handler element |
swiper.scrollbar.el | HTMLElement | HTMLElement of Scrollbar container element |
Methods | ||
swiper.scrollbar.destroy() | Destroy scrollbar | |
swiper.scrollbar.init() | Initialize scrollbar | |
swiper.scrollbar.setTranslate() | Updates scrollbar translate | |
swiper.scrollbar.updateSize() | Updates scrollbar track and handler sizes |
Name | Arguments | Description |
---|---|---|
scrollbarDragEnd | (swiper, event) | Event will be fired on draggable scrollbar drag end |
scrollbarDragMove | (swiper, event) | Event will be fired on draggable scrollbar drag move |
scrollbarDragStart | (swiper, event) | Event will be fired on draggable scrollbar drag start |
--swiper-scrollbar-border-radius: 10px;
--swiper-scrollbar-top: auto;
--swiper-scrollbar-bottom: 4px;
--swiper-scrollbar-left: auto;
--swiper-scrollbar-right: 4px;
--swiper-scrollbar-sides-offset: 1%;
--swiper-scrollbar-bg-color: rgba(0, 0, 0, 0.1);
--swiper-scrollbar-drag-bg-color: rgba(0, 0, 0, 0.5);
--swiper-scrollbar-size: 4px;
Name | Type | Default | Description |
---|---|---|---|
autoplay | boolean | AutoplayOptions | Object with autoplay parameters or boolean
| |
{ | |||
delay | number | 3000 | Delay between transitions (in ms). If this parameter is not specified, auto play will be disabled If you need to specify different delay for specific slides you can do it by using
|
disableOnInteraction | boolean | true | Set to |
pauseOnMouseEnter | boolean | false | When enabled autoplay will be paused on pointer (mouse) enter over Swiper container. |
reverseDirection | boolean | false | Enables autoplay in reverse direction |
stopOnLastSlide | boolean | false | Enable this parameter and autoplay will be stopped when it reaches last slide (has no effect in loop mode) |
waitForTransition | boolean | true | When enabled autoplay will wait for wrapper transition to continue. Can be disabled in case of using Virtual Translate when your slider may not have transition |
} |
Properties | ||
---|---|---|
swiper.autoplay.paused | boolean | Whether autoplay is paused |
swiper.autoplay.running | boolean | Whether autoplay enabled and running |
swiper.autoplay.timeLeft | number | If autoplay is paused, it contains time left (in ms) before transition to next slide |
Methods | ||
swiper.autoplay.pause() | Pause autoplay | |
swiper.autoplay.resume() | Resume autoplay | |
swiper.autoplay.start() | Start autoplay | |
swiper.autoplay.stop() | Stop autoplay |
Name | Arguments | Description |
---|---|---|
autoplay | (swiper) | Event will be fired when slide changed with autoplay |
autoplayPause | (swiper) | Event will be fired on autoplay pause |
autoplayResume | (swiper) | Event will be fired on autoplay resume |
autoplayStart | (swiper) | Event will be fired in when autoplay started |
autoplayStop | (swiper) | Event will be fired when autoplay stopped |
autoplayTimeLeft | (swiper, timeLeft, percentage) | Event triggers continuously while autoplay is enabled. It contains time left (in ms) before transition to next slide and percentage of that time related to autoplay delay |
Name | Type | Default | Description |
---|---|---|---|
freeMode | boolean | FreeModeOptions | Enables free mode functionality. Object with free mode parameters or boolean
| |
{ | |||
enabled | boolean | false | Whether the free mode is enabled |
minimumVelocity | number | 0.02 | Minimum touchmove-velocity required to trigger free mode momentum |
momentum | boolean | true | If enabled, then slide will keep moving for a while after you release it |
momentumBounce | boolean | true | Set to |
momentumBounceRatio | number | 1 | Higher value produces larger momentum bounce effect |
momentumRatio | number | 1 | Higher value produces larger momentum distance after you release slider |
momentumVelocityRatio | number | 1 | Higher value produces larger momentum velocity after you release slider |
sticky | boolean | false | Set to enabled to enable snap to slides positions in free mode |
} |
Name | Type | Default | Description |
---|---|---|---|
grid | GridOptions | Object with grid parameters to enable "multirow" slider.
| |
{ | |||
fill | 'row' | 'column' | 'column' | Can be |
rows | number | 1 | Number of slides rows, for multirow layout
|
} |
Manipulation module adds useful Swiper methods to manipulate slides. It makes sense to use it only with Swiper Core version, not intended to be uses with Swiper React or Vue.
Methods | ||
---|---|---|
swiper.addSlide(index, slides) | Add new slides to the required index. slides could be HTMLElement or HTML string with new slide or array with such slides, for example:
| |
swiper.appendSlide(slides) | Add new slides to the end. slides could be HTMLElement or HTML string with new slide or array with such slides, for example:
| |
swiper.prependSlide(slides) | Add new slides to the beginning. slides could be HTMLElement or HTML string with new slide or array with such slides, for example:
| |
swiper.removeAllSlides() | Remove all slides | |
swiper.removeSlide(slideIndex) | Remove selected slides. slideIndex could be a number with slide index to remove or array with indexes.
|
Swiper supports parallax transition effects for swiper/slides nested elements. There are two types of parallax elements supported:
swiper
. Parallax effect for such elements will depend on total slider progress. Useful for parallax backgroundsTo enable parallax effects you need to init Swiper with passed parallax:true
parameter and add one of the following (or mix) attributes to required elements:
data-swiper-parallax
- enable transform-translate parallax transition. This attribute may accept:
number
- value in px (as for title, subtitle in example above) to move element depending on progress. In this case such element will be moved on ± this value in px depending on slide position (next or previous)percentage
- (as for "parallax-bg") to move element depending on progress and on its size. In this case such element will be moved on ± this percentage of its size (width in horizontal direction, and height in vertical direction) depending on slide position (next or previous). So if element has 400px width and you specified data-swiper-parallax="50%" then it will be moved on ± 200pxdata-swiper-parallax-x
- same but for x-axis directiondata-swiper-parallax-y
- same but for y-axis directiondata-swiper-parallax-scale
- scale ratio of the parallax element when it is in "inactive" (not on active slide) statedata-swiper-parallax-opacity
- opacity of the parallax element when it is in "inactive" (not on active slide) statedata-swiper-parallax-duration
- custom transition duration for parallax elements<div class="swiper">
<!-- Parallax background element -->
<div
class="parallax-bg"
style="background-image:url(path/to/image.jpg)"
data-swiper-parallax="-23%"
></div>
<div class="swiper-wrapper">
<div class="swiper-slide">
<!-- Each slide has parallax title -->
<div class="title" data-swiper-parallax="-100">Slide 1</div>
<!-- Parallax subtitle -->
<div class="subtitle" data-swiper-parallax="-200">Subtitle</div>
<!-- And parallax text with custom transition duration -->
<div
class="text"
data-swiper-parallax="-300"
data-swiper-parallax-duration="600"
>
<p>Lorem ipsum dolor sit amet, ...</p>
</div>
<!-- Opacity parallax -->
<div data-swiper-parallax-opacity="0.5">I will change opacity</div>
<!-- Scale parallax -->
<div data-swiper-parallax-scale="0.15">I will change scale</div>
</div>
...
</div>
</div>
Name | Type | Default | Description |
---|---|---|---|
parallax | boolean | ParallaxOptions | Object with parallax parameters or boolean
| |
{ | |||
enabled | boolean | false | Enable, if you want to use "parallaxed" elements inside of slider |
} |
Since version 9 Swiper doesn't have a specific lazy loading API, as it relies on native browser lazy loading feature. To use lazy loading, we just need to set loading="lazy"
on images and add preloader element:
<div class="swiper">
<div class="swiper-wrapper">
<!-- Lazy image -->
<div class="swiper-slide">
<img src="path/to/picture-1.jpg" loading="lazy" />
<div class="swiper-lazy-preloader"></div>
</div>
<!-- Lazy image with srcset -->
<div class="swiper-slide">
<img
src="path/to/logo-small.png"
srcset="path/to/logo-large.png 2x"
loading="lazy"
/>
<div class="swiper-lazy-preloader"></div>
</div>
</div>
</div>
As you see:
loading="lazy"
attribute<div class="swiper-lazy-preloader"></div>
Or white one for dark layout:
<div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div>
Be sure to have the effect
param set to 'fade'
in order for this to work.
crossFade
should be set to true
in order to avoid seeing content behind or underneath.Name | Type | Default | Description |
---|---|---|---|
fadeEffect | FadeEffectOptions | Object with Fade-effect parameters
| |
{ | |||
crossFade | boolean | false | Enables slides cross fade |
} |
Be sure to have the effect
param set to 'coverflow'
in order for this to work.
Name | Type | Default | Description |
---|---|---|---|
coverflowEffect | CoverflowEffectOptions | Object with Coverflow-effect parameters.
| |
{ | |||
depth | number | 100 | Depth offset in px (slides translate in Z axis) |
modifier | number | 1 | Effect multiplier |
rotate | number | 50 | Slide rotate in degrees |
scale | number | 1 | Slide scale effect |
slideShadows | boolean | true | Enables slides shadows |
stretch | number | 0 | Stretch space between slides (in px) |
} |
Be sure to have the effect
param set to 'flip'
in order for this to work.
Name | Type | Default | Description |
---|---|---|---|
flipEffect | FlipEffectOptions | Object with Flip-effect parameters
| |
{ | |||
limitRotation | boolean | true | Limit edge slides rotation |
slideShadows | boolean | true | Enables slides shadows |
} |
Be sure to have the effect
param set to 'cube'
in order for this to work.
Name | Type | Default | Description |
---|---|---|---|
cubeEffect | CubeEffectOptions | Object with Cube-effect parameters
| |
{ | |||
shadow | boolean | true | Enables main slider shadow |
shadowOffset | number | 20 | Main shadow offset in px |
shadowScale | number | 0.94 | Main shadow scale ratio |
slideShadows | boolean | true | Enables slides shadows |
} |
Be sure to have the effect
param set to 'cards'
in order for this to work.
Name | Type | Default | Description |
---|---|---|---|
cardsEffect | CardsEffectOptions | Object with Cards-effect parameters
| |
{ | |||
perSlideOffset | number | 8 | Offset distance per slide (in px) |
perSlideRotate | number | 2 | Rotate angle per slide (in degrees) |
rotate | boolean | true | Enables cards rotation |
slideShadows | boolean | true | Enables slides shadows |
} |
Be sure to have the effect
param set to 'creative'
in order for this to work.
Name | Type | Default | Description |
---|---|---|---|
creativeEffect | CreativeEffectOptions | Object with Creative-effect parameters
| |
{ | |||
limitProgress | number | 1 | Limit progress/offset to amount of side slides. If |
next | CreativeEffectTransform | Next slide transformations.
| |
perspective | boolean | true | Enable this parameter if your custom transforms require 3D transformations ( |
prev | CreativeEffectTransform | Previous slide transformations. Accepts object of the following type:
| |
progressMultiplier | number | 1 | Allows to multiply slides transformations and opacity. |
shadowPerProgress | boolean | false | Splits shadow "opacity" per slide based on |
} |
In addition to Controller component Swiper comes with Thumbs component that is designed to work with additional thumbs swiper in a more correct way than Controller which is used for syncing two swipers.
Name | Type | Default | Description |
---|---|---|---|
thumbs | ThumbsOptions | Object with thumbs component parameters
| |
{ | |||
autoScrollOffset | number | 0 | Allows to set on which thumbs active slide from edge it should automatically move scroll thumbs. For example, if set to 1 and last visible thumb will be activated (1 from edge) it will auto scroll thumbs |
multipleActiveThumbs | boolean | true | When enabled multiple thumbnail slides may get activated |
slideThumbActiveClass | string | 'swiper-slide-thumb-active' | Additional class that will be added to activated thumbs swiper slide |
swiper | null | Swiper | null | Swiper instance of swiper used as thumbs or object with Swiper parameters to initialize thumbs swiper |
thumbsContainerClass | string | 'swiper-thumbs' | Additional class that will be added to thumbs swiper |
} |
Properties | ||
---|---|---|
swiper.thumbs.swiper | Swiper | Swiper instance of thumbs swiper |
Methods | ||
swiper.thumbs.init() | Initialize thumbs | |
swiper.thumbs.update(initial) | Update thumbs |
Swiper supports zoom images functionality (similar to what you see on iOS when browsing single photo) where you can zoom-in image by pinch gesture and or by zoom-in/out by double tap on it. In this case, additional layout is required:
<div class="swiper">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="swiper-zoom-container">
<img src="path/to/image1.jpg" />
</div>
</div>
<div class="swiper-slide">
<div class="swiper-zoom-container">
<img src="path/to/image2.jpg" />
</div>
</div>
<div class="swiper-slide">Plain slide with text</div>
<div class="swiper-slide">
<!-- Override maxRatio parameter -->
<div class="swiper-zoom-container" data-swiper-zoom="5">
<img src="path/to/image1.jpg" />
</div>
</div>
</div>
</div>
swiper-zoom-container
class.img
, picture
or canvas
element. If you want to make zoom on some other custom element, then just add swiper-zoom-target
class to this element. For example:
<div class="swiper">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="swiper-zoom-container">
<!-- custom zoomable element -->
<div
class="swiper-zoom-target"
style="background-image: url(...)"
></div>
</div>
</div>
</div>
</div>
maxRatio
parameter for specific slides by using data-swiper-zoom
attribute on zoom container.Name | Type | Default | Description |
---|---|---|---|
zoom | boolean | ZoomOptions | Enables zooming functionality. Object with zoom parameters or boolean
| |
{ | |||
containerClass | string | 'swiper-zoom-container' | CSS class name of zoom container |
maxRatio | number | 3 | Maximum image zoom multiplier |
minRatio | number | 1 | Minimal image zoom multiplier |
toggle | boolean | true | Enable/disable zoom-in by slide's double tap |
zoomedSlideClass | string | 'swiper-slide-zoomed' | CSS class name of zoomed in container |
} |
Properties | ||
---|---|---|
swiper.zoom.enabled | boolean | Whether the zoom module is enabled |
swiper.zoom.scale | number | Current image scale ratio |
Methods | ||
swiper.zoom.disable() | Disable zoom module | |
swiper.zoom.enable() | Enable zoom module | |
swiper.zoom.in(ratio) | Zoom in image of the currently active slide. Optionally accepts custom zoom ratio | |
swiper.zoom.out() | Zoom out image of the currently active slide | |
swiper.zoom.toggle() | Toggle image zoom of the currently active slide |
Name | Arguments | Description |
---|---|---|
zoomChange | (swiper, scale, imageEl, slideEl) | Event will be fired on zoom change |
Name | Type | Default | Description |
---|---|---|---|
keyboard | boolean | KeyboardOptions | Enables navigation through slides using keyboard. Object with keyboard parameters or boolean
| |
{ | |||
enabled | boolean | false | Set to |
onlyInViewport | boolean | true | When enabled it will control sliders that are currently in viewport |
pageUpDown | boolean | true | When enabled it will enable keyboard navigation by Page Up and Page Down keys |
} |
Properties | ||
---|---|---|
swiper.keyboard.enabled | boolean | Whether the keyboard control is enabled |
Methods | ||
swiper.keyboard.disable() | Disable keyboard control | |
swiper.keyboard.enable() | Enable keyboard control |
Name | Arguments | Description |
---|---|---|
keyPress | (swiper, keyCode) | Event will be fired on key press |
Name | Type | Default | Description |
---|---|---|---|
mousewheel | boolean | MousewheelOptions | Enables navigation through slides using mouse wheel. Object with mousewheel parameters or boolean
| |
{ | |||
eventsTarget | HTMLElement | 'container' | 'wrapper' | CSSSelector | 'container' | String with CSS selector or HTML element of the container accepting mousewheel events. By default it is swiper |
forceToAxis | boolean | false | Set to |
invert | boolean | false | Set to |
noMousewheelClass | string | 'swiper-no-mousewheel' | Scrolling on elements with this class will be ignored |
releaseOnEdges | boolean | false | Set to |
sensitivity | number | 1 | Multiplier of mousewheel data, allows to tweak mouse wheel sensitivity |
thresholdDelta | null | number | null | Minimum mousewheel scroll delta to trigger swiper slide change |
thresholdTime | null | number | null | Minimum mousewheel scroll time delta (in ms) to trigger swiper slide change |
} |
Properties | ||
---|---|---|
swiper.mousewheel.enabled | boolean | Whether the mousewheel control is enabled |
Methods | ||
swiper.mousewheel.disable() | Disable mousewheel control | |
swiper.mousewheel.enable() | Enable mousewheel control |
Name | Arguments | Description |
---|---|---|
scroll | (swiper, event) | Event will be fired on mousewheel scroll |
Virtual Slides module allows to keep just required amount of slides in DOM. It is very useful in terms in performance and memory issues if you have a lot of slides, especially slides with heavyweight DOM tree or images.
slidesPerView: 'auto'
Name | Type | Default | Description |
---|---|---|---|
virtual | boolean | VirtualOptions | Enables virtual slides functionality. Object with virtual slides parameters or boolean
| |
{ | |||
addSlidesAfter | number | 0 | Increases amount of pre-rendered slides after active slide |
addSlidesBefore | number | 0 | Increases amount of pre-rendered slides before active slide |
cache | boolean | true | Enables DOM cache of rendering slides html elements. Once they are rendered they will be saved to cache and reused from it. |
enabled | boolean | false | Whether the virtual slides are enabled |
renderExternal | function(data) | Function for external rendering (e.g. using some other library to handle DOM manipulations and state like React.js or Vue.js). As an argument it accepts
| |
renderExternalUpdate | boolean | true | When enabled (by default) it will update Swiper layout right after renderExternal called. Useful to disable and update swiper manually when used with render libraries that renders asynchronously |
renderSlide | function(slide, index) | Function to render slide. As an argument it accepts current slide item for | |
slides | any[] | [] | Array with slides |
} |
Properties | ||
---|---|---|
swiper.virtual.cache | object | Object with cached slides HTML elements |
swiper.virtual.from | number | Index of first rendered slide |
swiper.virtual.slides | any[] | Array with slide items passed by |
swiper.virtual.to | number | Index of last rendered slide |
Methods | ||
swiper.virtual.appendSlide(slide) | Append slide.
| |
swiper.virtual.prependSlide(slide) | Prepend slide.
| |
swiper.virtual.removeAllSlides() | Remove all slides
| |
swiper.virtual.removeSlide(slideIndexes) | Remove specific slide or slides.
| |
swiper.virtual.update(force) | Update virtual slides state |
Since version 9, Swiper virtual slides can work with slides originally rendered in DOM. On initialize it will remove them from DOM, cache and then re-use the ones which are required:
<div class="swiper">
<div class="swiper-wrapper">
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
...
<div class="swiper-slide">Slide 100</div>
</div>
</div>
<script>
const swiper = new Swiper('.swiper', {
virtual: {
enabled: true,
},
});
</script>
Hash navigation is intended to have a link to specific slide that allows to load page with specific slide opened.
To make it work, you need to enable it by passing hashNavigation:true
parameter and adding slides hashes in data-hash
attribute:
<div class="swiper">
<div class="swiper-wrapper">
<div class="swiper-slide" data-hash="slide1">Slide 1</div>
<div class="swiper-slide" data-hash="slide2">Slide 2</div>
<div class="swiper-slide" data-hash="slide3">Slide 3</div>
<div class="swiper-slide" data-hash="slide4">Slide 4</div>
<div class="swiper-slide" data-hash="slide5">Slide 5</div>
...
</div>
</div>
const swiper = new Swiper('.swiper', {
//enable hash navigation
hashNavigation: true,
});
Name | Type | Default | Description |
---|---|---|---|
hashNavigation | boolean | HashNavigationOptions | Enables hash url navigation to for slides. Object with hash navigation parameters or boolean
| |
{ | |||
getSlideIndex | function(swiper, hash) | Designed to be used with Virtual slides when it is impossible to find slide in DOM by hash (e.g. not yet rendered) | |
replaceState | boolean | false | Works in addition to hashnav to replace current url state with the new one instead of adding it to history |
watchState | boolean | false | Set to |
} |
Name | Arguments | Description |
---|---|---|
hashChange | (swiper) | Event will be fired on window hash change |
hashSet | (swiper) | Event will be fired when swiper updates the hash |
Name | Type | Default | Description |
---|---|---|---|
history | boolean | HistoryOptions | Enables history push state where every slide will have its own url. In this parameter you have to specify main slides url like Object with history navigation parameters or boolean
| |
{ | |||
enabled | boolean | false | Enables History Plugin. |
keepQuery | boolean | false | Keep query parameters when changing browser url. |
key | string | 'slides' | Url key for slides |
replaceState | boolean | false | Works in addition to hashnav or history to replace current url state with the new one instead of adding it to history |
root | string | '' | Swiper page root, useful to specify when you use Swiper history mode not on root website page. For example can be |
} |
Name | Type | Default | Description |
---|---|---|---|
controller | ControllerOptions | Object with controller parameters or boolean
| |
{ | |||
by | 'slide' | 'container' | 'slide' | Defines a way how to control another slider: slide by slide (with respect to other slider's grid) or depending on all slides/container (depending on total slider percentage). |
control | null | string | Swiper | Swiper[] | HTMLElement | Pass here another Swiper instance or array with Swiper instances that should be controlled by this Swiper. Also accepts string with CSS selector of Swiper element, or HTMLElement of Swiper element | |
inverse | boolean | false | Set to |
} |
Properties | ||
---|---|---|
swiper.controller.control | Swiper | Swiper[] | Pass here another Swiper instance or array with Swiper instances that should be controlled by this Swiper |
Name | Type | Default | Description |
---|---|---|---|
a11y | A11yOptions | Object with a11y parameters or boolean
| |
{ | |||
containerMessage | null | string | null | Message for screen readers for outer swiper container |
containerRoleDescriptionMessage | null | string | null | Message for screen readers describing the role of outer swiper container |
enabled | boolean | true | Enables A11y |
firstSlideMessage | string | 'This is the first slide' | Message for screen readers for previous button when swiper is on first slide |
id | null | string | number | null | Value of |
itemRoleDescriptionMessage | null | string | null | Message for screen readers describing the role of slide element |
lastSlideMessage | string | 'This is the last slide' | Message for screen readers for next button when swiper is on last slide |
nextSlideMessage | string | 'Next slide' | Message for screen readers for next button |
notificationClass | string | 'swiper-notification' | CSS class name of A11y notification |
paginationBulletMessage | string | 'Go to slide {{index}}' | Message for screen readers for single pagination bullet |
prevSlideMessage | string | 'Previous slide' | Message for screen readers for previous button |
slideLabelMessage | string | '{{index}} / {{slidesLength}}' | Message for screen readers describing the label of slide element |
slideRole | string | 'group' | Value of swiper slide |
} |
You have two options of making custom version of Swiper.
If you use bundler with JS modules support in your project you can import only the modules you need:
// Import Swiper and modules
import Swiper, { Navigation, Pagination, Scrollbar } from 'swiper';
// Now you can use Swiper
const swiper = new Swiper('.swiper', {
// Install modules
modules: [Navigation, Pagination, Scrollbar],
speed: 500,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// ...
});
The following modules are exported:
Virtual
- Virtual Slides moduleKeyboard
- Keyboard Control moduleMousewheel
- Mousewheel Control moduleNavigation
- Navigation modulePagination
- Pagination moduleScrollbar
- Scrollbar moduleParallax
- Parallax moduleFreeMode
- Free Mode moduleGrid
- Grid moduleManipulation
- Slides manipulation module (only for Core version)Zoom
- Zoom moduleController
- Controller moduleA11y
- Accessibility moduleHistory
- History Navigation moduleHashNavigation
- Hash Navigation moduleAutoplay
- Autoplay moduleEffectFade
- Fade Effect moduleEffectCube
- Cube Effect moduleEffectFlip
- Flip Effect moduleEffectCoverflow
- Coverflow Effect moduleEffectCards
- Cards Effect moduleEffectCreative
- Creative Effect moduleThumbs
- Thumbs moduleSwiper comes with gulp builder that allows to build custom library version where you may include only required modules. We need the following:
Download and unzip Swiper GitHub repository to local folder
Install Node.js (if not installed)
Now, we need to install required dependencies. Go to the folder with downloaded and unzipped Swiper repository and execute in terminal:
$ npm install
Open scripts/build-config.js
file:
module.exports = {
// remove modules you don't need
modules: [
'virtual',
'keyboard',
'mousewheel',
'navigation',
'pagination',
'scrollbar',
'parallax',
'zoom',
'controller',
'a11y',
'history',
'hash-navigation',
'autoplay',
'thumbs',
'free-mode',
'grid',
'manipulation',
'effect-fade',
'effect-cube',
'effect-flip',
'effect-coverflow',
'effect-creative',
'effect-cards',
],
};
Now, we are ready to build custom version of Swiper:
$ npm run build:prod
That is all. Generated CSS and JS files and their minified versions will be available in dist/
folder.
Swiper is fully typed, it exports Swiper
and SwiperOptions
types:
// main.ts
import { Swiper, SwiperOptions } from 'swiper';
const swiperParams: SwiperOptions = {
slidesPerView: 3,
spaceBetween: 50,
};
const swiper = new Swiper('.swiper', swiperParams);
You can also check auto generated TypeScript definitions explorer for all the types, options, properties and methods.