Ver Fonte

Bug Fix: Need to shift the carousel when it crosses bounds.

Naotoshi Fujita há 3 anos atrás
pai
commit
bac10d9580

+ 3 - 2
dist/js/splide.cjs.js

@@ -1427,10 +1427,11 @@ function Move(Splide2, Components2, options) {
 
   function move(dest, index, prev, callback) {
     var position = getPosition();
+    var crossing = sign(dest - prev) * orient(toPosition(dest) - position) < 0;
 
-    if (dest !== index && canShift(dest > index)) {
+    if ((dest !== index || crossing) && canShift(dest > prev)) {
       cancel();
-      translate(shift(position, dest > index), true);
+      translate(shift(position, dest > prev), true);
     }
 
     set(MOVING);

+ 3 - 2
dist/js/splide.esm.js

@@ -1422,10 +1422,11 @@ function Move(Splide2, Components2, options) {
 
   function move(dest, index, prev, callback) {
     var position = getPosition();
+    var crossing = sign(dest - prev) * orient(toPosition(dest) - position) < 0;
 
-    if (dest !== index && canShift(dest > index)) {
+    if ((dest !== index || crossing) && canShift(dest > prev)) {
       cancel();
-      translate(shift(position, dest > index), true);
+      translate(shift(position, dest > prev), true);
     }
 
     set(MOVING);

+ 3 - 2
dist/js/splide.js

@@ -1420,10 +1420,11 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
 
     function move(dest, index, prev, callback) {
       var position = getPosition();
+      var crossing = sign(dest - prev) * orient(toPosition(dest) - position) < 0;
 
-      if (dest !== index && canShift(dest > index)) {
+      if ((dest !== index || crossing) && canShift(dest > prev)) {
         cancel();
-        translate(shift(position, dest > index), true);
+        translate(shift(position, dest > prev), true);
       }
 
       set(MOVING);

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/js/splide.min.js


BIN
dist/js/splide.min.js.gz


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/js/splide.min.js.map


+ 4 - 3
src/js/components/Move/Move.ts

@@ -12,7 +12,7 @@ import { FADE, LOOP, SLIDE } from '../../constants/types';
 import { EventInterface } from '../../constructors';
 import { Splide } from '../../core/Splide/Splide';
 import { AnyFunction, BaseComponent, Components, Options, TransitionComponent } from '../../types';
-import { abs, ceil, clamp, isUndefined, rect, style } from '../../utils';
+import { abs, ceil, clamp, isUndefined, rect, sign, style } from '../../utils';
 
 
 /**
@@ -91,10 +91,11 @@ export function Move( Splide: Splide, Components: Components, options: Options )
    */
   function move( dest: number, index: number, prev: number, callback?: AnyFunction ): void {
     const position = getPosition();
+    const crossing = sign( dest - prev ) * orient( toPosition( dest ) - position ) < 0;
 
-    if ( dest !== index && canShift( dest > index ) ) {
+    if ( ( dest !== index || crossing ) && canShift( dest > prev ) ) {
       cancel();
-      translate( shift( position, dest > index ), true );
+      translate( shift( position, dest > prev ), true );
     }
 
     set( MOVING );

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff