mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[new feature] Swipe: support disable loop (#670)
This commit is contained in:
parent
9027c3e8b4
commit
8e7930033b
@ -72,6 +72,7 @@ export default {
|
||||
|-----------|-----------|-----------|-------------|-------------|
|
||||
| autoplay | Autoplay interval (ms) | `Number` | - | - |
|
||||
| duration | Animation duration (ms) | `Number` | `500` | - |
|
||||
| loop | Whether to enable loop | `Boolean` | `true` | - |
|
||||
| show-indicators | Whether to show indocators | `Boolean` | `true` | - |
|
||||
| initial-swipe | Index of initial swipe, start from 0 | `Number` | `0` | - |
|
||||
|
||||
|
@ -72,6 +72,7 @@ export default {
|
||||
|-----------|-----------|-----------|-------------|-------------|
|
||||
| autoplay | 自动轮播间隔,单位为 ms | `Number` | - | - |
|
||||
| duration | 动画时长,单位为 ms | `Number` | `500` | - |
|
||||
| loop | 是否开启循环播放 | `Boolean` | `true` | - |
|
||||
| show-indicators | 是否显示指示器 | `Boolean` | `true` | - |
|
||||
| initial-swipe | 初始位置,从 0 开始算 | `Number` | `0` | - |
|
||||
|
||||
|
@ -29,6 +29,10 @@ export default create({
|
||||
|
||||
props: {
|
||||
autoplay: Number,
|
||||
loop: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
initialSwipe: {
|
||||
type: Number,
|
||||
default: 0
|
||||
@ -152,6 +156,14 @@ export default create({
|
||||
move(move = 0, offset = 0) {
|
||||
const { active, count, swipes, deltaX, width } = this;
|
||||
|
||||
if (
|
||||
!this.loop &&
|
||||
((active === 0 && (offset > 0 || move < 0)) ||
|
||||
(active === count - 1 && (offset < 0 || move > 0)))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (move) {
|
||||
if (active === -1) {
|
||||
swipes[count - 1].offset = 0;
|
||||
@ -190,9 +202,9 @@ export default create({
|
||||
},
|
||||
|
||||
getDirection(touch) {
|
||||
const distanceX = Math.abs(touch.clientX - this.startX);
|
||||
const distanceY = Math.abs(touch.clientY - this.startY);
|
||||
return distanceX > distanceY ? 'horizontal' : distanceX < distanceY ? 'vertical' : '';
|
||||
const offsetX = Math.abs(touch.clientX - this.startX);
|
||||
const offsetY = Math.abs(touch.clientY - this.startY);
|
||||
return offsetX > offsetY ? 'horizontal' : offsetX < offsetY ? 'vertical' : '';
|
||||
},
|
||||
|
||||
range(num, arr) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user