Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Vue Concise Carousel with True SSR Written for Jambon

License

NotificationsYou must be signed in to change notification settings

jambonn/vue-concise-carousel

Repository files navigation

Vue Concise Carousel is SSR and CSR friendly.An upgraded version fromvue-carousel

Vue 3 support is almost here with the vue-concise-carousel 2 rewrite. Check out thenext branch to see the latest progress.

Full examples

Table of Contents

Installation

npm install @jambonn/vue-concise-carousel@next

or if you prefer yarn

yarn add @jambonn/vue-concise-carousel@next

Usage

Global

You may install Vue Concise Carousel globally:

importVuefrom'vue';import{Carousel,Slide}from'@jambonn/vue-concise-carousel';import'@jambonn/vue-concise-carousel/lib/vue-concise-carousel.css'Vue.component('carousel',Carousel);Vue.component('slide',Slide);

This will make<carousel> and<slide> available to all components within your Vue app.

Local

Include the carousel directly into your component using import:

import{Carousel,Slide}from'@jambonn/vue-concise-carousel';import'@jambonn/vue-concise-carousel/lib/vue-concise-carousel.css'exportdefault{  ...components:{Carousel,    Slide}...};

Configuration

PropertyTypeDefaultDescription
adjustableHeightBooleanfalseAdjust the height of the carousel for the current slide.
adjustableHeightEasingStringSlide transition easing for adjustableHeight. Any valid CSS transition easing accepted.
autoplayBooleanfalseFlag to enable autoplay.
autoplayDirectionStringforwardSets the autoplay direction for the carousel during autoplay. By default it is forward but can also be set to backward. If an incorrect string is supplied it will default to forward.
autoplayHoverPauseBooleantrueFlag to pause autoplay on hover.
autoplayTimeoutNumber2000Time elapsed before advancing slide in autoplay.
centerModeBooleanfalseCenter images when the size is less than the container width.
easingStringeaseSlide transition easing. Any valid CSS transition easing accepted.
loopBooleanfalseFlag to make the carousel loop around when it reaches the end.
minSwipeDistanceNumber8Minimum distance for the swipe to trigger a slide advance.
mouseDragBooleantrueFlag to toggle mouse dragging.
navigateToNumber, Array0Listen for an external navigation request using this prop. When the supplied prop is of type Number the slide with the matching index is animated into view, however you can disable this animation by supplying an Array consisting of exactly two element: the new slide index and a boolean indication whether the change should be animated or not (eg. [3, false] would mean "go to the slide with index 3 without animation").
navigationClickTargetSizeNumber8Amount of padding to apply around the label in pixels.
navigationEnabledBooleanfalseFlag to render the navigation component (next/prev buttons).
navigationNextLabelStringText content of the navigation next button.
navigationPrevLabelStringText content of the navigation prev button.
paginationActiveColorString#000000The fill color of the active pagination dot. Any valid CSS color is accepted.
paginationColorString#efefefThe fill color of pagination dots. Any valid CSS color is accepted.
paginationPositionStringbottomThe position of pagination dots. Possible values arebottom,bottom-overlay,top andtop-overlay. The overlay values place the pagination component over the images.
paginationEnabledBooleantrueFlag to render pagination component.
paginationPaddingNumber10The padding inside each pagination dot. Pixel values are accepted.
paginationSizeNumber10The size of each pagination dot. Pixel values are accepted.
perPageNumber2Maximum number of slides displayed on each page.
perPageCustomArrayConfigure the number of visible slides with a particular browser width. This will be an array of arrays, ex. [[320, 2], [1199, 4]]. Formatted as [x, y] where x=browser width, and y=number of slides displayed. Ex. [1199, 4] means if (window >= 1199) then show 4 slides per page.
resistanceCoefNumber20Resistance coefficient to dragging on the edge of the carousel. This dictates the effect of the pull as you move towards the boundaries.
scrollPerPageBooleantrueScroll per page, not per item.
spacePaddingNumber0Stage padding option adds left and right padding style (in pixels) onto VueCarousel-inner.
spacePaddingMaxOffsetFactorNumber0Specify by how much should the space padding value be multiplied of, to re-arange the final slide padding.
speedNumber500Slide transition speed. Number of milliseconds accepted.
tagNameStringslideName (tag) of slide component. Overwrite with coponent name when extending slide component.
touchDragBooleantrueFlag to toggle touch dragging.
valueNumberSupport for v-model functionality. Setting this value will change the current page to the number inputted (if between 0 and pageCount).
maxPaginationDotCountNumber-1Support Max pagination dot amount
rtlBooleanfalseSupport right to left
keyboardBooleanfalseNavigate slide using keyboard
resizeObserverBooleanfalseUse ResizeObserver

Events

EventTypeEmitterDescription
navigation-clickCarouselEmits when the a navigation button is clicked, with the current direction (backward orforward)
pagination-clickCarouselEmits when a pagination button is clicked, with the currentpageNumber
page-changeNumberCarouselEmits with the current page number.
slide-clickObjectSlideEmits with thedataset object of the selected element ··
transition-startCarouselEmits when the transition end is reached
transition-endCarouselEmits when the transition start is reached ·
mountedCarouselEmits when carousel ready ·

Lowercase versions of the above events are also emitted, namely—pagechange,slideclick,transitionstart andtransitionend.

HTML Structure

Once theCarousel andSlide components are installed globally or imported, they can be used in templates in the following manner:

  <Carousel :per-page="1" :navigate-to="someLocalProperty" :mouse-drag="false">    <Slide>      Slide 1 Content    </Slide>    <Slide>      Slide 2 Content    </Slide>  </Carousel>

To listen for the 'slide-click' event you can do the following:

  <Carousel>    <Slide        data-index="0"        data-name="MySlideName"        @slide-click="handleSlideClick">      Slide 1 Content    </Slide>    ...  </Carousel>
handleSlideClick(dataset)=>{console.log(dataset.index,dataset.name)}

Methods

Calling Methods

<template><Carouselref="carousel"><Slide>      Slide 1 Content</Slide><Slide>      Slide 2 Content</Slide></Carousel><button@click="showNext">show me the next</button></template><script>exportdefault{methods:{showNext(){this.$refs.carousel.handleNavigation('forward')},},}</script>

All Methods

Method nameDescriptionReturnsParametersDefault
handleNavigationgo to the next or previous slide-direction: forward or backward-
goToPagego to slide index-slide:Number - slide numbernull
restartAutoplayrestarts the autoplay-
pauseAutoplaypauses the autoplay-

Slots

Customizing Navigation & Pagination

<template><Carouselref="carousel"@page-change="handlePageChange"><Slide>        Slide 1 Content</Slide><Slide>        Slide 2 Content</Slide><divclass="custom-navigation"slot="navigation"><buttontype="button":disabled="currentPage > 0"@click="onChangeNavigation('backward')">Back</button><buttontype="button":disabled="!isEnableForward"@click="onChangeNavigation('forward')">Next</button></div><ulclass="custom-pagination"slot="pagination"><li@click="onChangePagination(1)">1</li><li@click="onChangePagination(2)">2</li></ul></Carousel></template><script>exportdefault{data(){return{currentPage:0,isEnableForward:true,}},methods:{handlePageChange(currentPage){this.currentPage=currentPagethis.isEnableForward=this.$refs.carousel.canAdvanceForward},onChangePagination(index){this.$refs.carousel.goToPage(index,'pagination')},onChangeNavigation(direction){this.$refs.carousel.handleNavigation(direction)},},}</script>

All Slots

NameDescriptionMethod
paginationCustom paginationgoToPage(currentSlide: Number)
navigationCustom navigationhandleNavigation(direction: String)

Compiles and hot-reloads for development

yarn installyarn dev

then navigate tohttp://localhost:8080

Compiles and minifies for production

yarn build

Lints and fixes files

yarn lint

License

This project is licensed under the MIT License - see theLICENSE.md file for details.

About

Vue Concise Carousel with True SSR Written for Jambon

Topics

Resources

License

Stars

Watchers

Forks

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp