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

😃 A siwpe (touch slider) component for Vue2

License

NotificationsYou must be signed in to change notification settings

pspgbhu/vue-swipe-mobile

Repository files navigation

English |简体中文

c-swipe

gzipnpm packageNPM downloadsGitHub issuesTravis

NPM

A swipe (touch slide) component for Vue2.x in mobile device.Only support touch event now.

c-swipe

Install

npm install c-swipe --save

Usage

register components:

// main.js// import c-swipe files into main.jsimport'c-swipe/dist/swipe.css';import{Swipe,SwipeItem}from'c-swipe';// global register componentsVue.component('swipe',Swipe);Vue.component('swipe-item',SwipeItem);

Use in.vue files.

<swipev-model="index"style="text-align: center; line-height: 80px; height: 100px; background: #42b983;"><swipe-itemstyle="height: 100px; line-height: 100px">item1</swipe-item><swipe-itemstyle="height: 100px; line-height: 100px">item2</swipe-item><swipe-itemstyle="height: 100px; line-height: 100px">item3</swipe-item></swipe>
newVue({data:function(){return{index:0,// two way};},});

Or, you want import it by html tag

<linkhref="https://unpkg.com/c-swipe/dist/swipe.css"rel="stylesheet"></head><scripttype="text/javascript"src="https://unpkg.com/c-swipe/dist/swipe.js"></script>
varvueSwipe=swipe.Swipe;varvueSwipeItem=swipe.SwipeItem;newVue({el:'body',// register componentscomponents:{'swipe':vueSwipe,'swipe-item':vueSwipeItem}// ...// ...});

Options

OptionTypeDefalutDescription
v-modelNumber0The value binding index of swipe-item
paginationBooleantrueIf need default pagination.
loopBooleantrueloop move
autoplayTimeNumber0ms. Interval time of change card. The card will not auto change when this value is equal to 0
speedNumber300ms, the spend time of change card.
minMoveDistanceString'20%'Such as '20%', '80px'. The minimum distance that trigger to change card

Methods

  • swipe.reset()

The c-swipe internally recalculates the width of the Swipe and calculates the scroll distance based on the new width. This solves the problem that the c-swipe scroll distance is not correct after the container is resized.

Example:

<swiperef="swipe"><swipe-item>item1</swipe-item><swipe-item>item2</swipe-item><swipe-item>item3</swipe-item></swipe><script>exportdefault{// ...// ...mounted(){// Avoid losing contextthis.handleResize=this.handleResize.bind(this);window.addEventListener('resize',this.handleResize);},destroyed(){window.removeEventListener('resize',this.handleResize);},methods:{handleResize(){this.$refs.swipe.reset();},},// ...// ...}</script>

Preview

Scan the QR code below to preview

c-swpie

License

MIT

About

😃 A siwpe (touch slider) component for Vue2

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp