File tree 4 files changed +22
-9
lines changed
4 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ const handleReset = () => {
171
171
items .splice (0 , items .length , ... defaultSlides )
172
172
}
173
173
174
- const handelButtonClick = () => {
174
+ const handleButtonClick = () => {
175
175
alert (' Button clicked' )
176
176
}
177
177
@@ -264,7 +264,7 @@ onMounted(() => {
264
264
>
265
265
<h3 >{{ item.title }}</h3 >
266
266
<p >{{ item.description }}</p >
267
- <button @click =" handelButtonClick " >This is a button</button >
267
+ <button @click =" handleButtonClick " >This is a button</button >
268
268
</div >
269
269
</CarouselSlide >
270
270
<template #addons >
Original file line number Diff line number Diff line change 7
7
height : var (--vc-carousel-height );
8
8
overscroll-behavior : none;
9
9
position : relative;
10
- touch-action : pan-y ;
10
+ touch-action : pan-x pan-y pinch-zoom ;
11
11
z-index : 1 ;
12
12
}
13
13
Original file line number Diff line number Diff line change @@ -423,6 +423,11 @@ export const Carousel = defineComponent({
423
423
threshold,
424
424
} )
425
425
426
+ // Prevent unnecessary reactivity
427
+ if ( draggedSlides === 0 ) {
428
+ return
429
+ }
430
+
426
431
activeSlideIndex . value = config . wrapAround
427
432
? currentSlideIndex . value + draggedSlides
428
433
: getNumberInRange ( {
Original file line number Diff line number Diff line change @@ -35,7 +35,10 @@ export function useDrag(options: UseDragOptions) {
35
35
36
36
isTouch = event . type === 'touchstart'
37
37
38
- if ( ! isTouch ) {
38
+ if ( isTouch && ( event as TouchEvent ) . touches . length > 1 ) {
39
+ // If there is more than 1 finger on the screen, avoid drag start (this allows user to pinch zoom)
40
+ return
41
+ } else if ( ! isTouch ) {
39
42
event . preventDefault ( )
40
43
if ( ( event as MouseEvent ) . button !== 0 ) {
41
44
return
@@ -58,6 +61,10 @@ export function useDrag(options: UseDragOptions) {
58
61
}
59
62
60
63
const handleDrag = throttle ( ( event : TouchEvent | MouseEvent ) : void => {
64
+ if ( isTouch && ( event as TouchEvent ) . touches . length > 1 ) {
65
+ return
66
+ }
67
+
61
68
isDragging . value = true
62
69
63
70
const currentX = isTouch
@@ -76,12 +83,13 @@ export function useDrag(options: UseDragOptions) {
76
83
const handleDragEnd = ( ) : void => {
77
84
handleDrag . cancel ( )
78
85
79
- if ( ! isTouch ) {
80
- const preventClick = ( e : MouseEvent ) => {
86
+ const draggedDistance = Math . abs ( dragged . x ) + Math . abs ( dragged . y ) ;
87
+
88
+ if ( ! isTouch && draggedDistance > 10 ) {
89
+ window . addEventListener ( 'click' , ( e : MouseEvent ) => {
81
90
e . preventDefault ( )
82
- window . removeEventListener ( 'click' , preventClick )
83
- }
84
- window . addEventListener ( 'click' , preventClick )
91
+ e . stopPropagation ( )
92
+ } , { once : true , capture : true } )
85
93
}
86
94
87
95
options . onDragEnd ?.( )
You can’t perform that action at this time.
0 commit comments