Explorar el Código

Autoplay can be resumed(#39).

NaotoshiFujita hace 5 años
padre
commit
3419c229c4

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

@@ -1220,6 +1220,13 @@ var DEFAULTS = {
    */
   pauseOnFocus: true,
 
+  /**
+   * Whether to reset progress of the autoplay timer when resumed.
+   *
+   * @type {boolean}
+   */
+  resetProgress: true,
+
   /**
    * Loading images lazily.
    * Image src must be provided by a data-splide-lazy attribute.
@@ -3581,6 +3588,10 @@ function createInterval(callback, interval, progress) {
     if (!_pause) {
       if (!start) {
         start = timestamp;
+
+        if (rate && rate < 1) {
+          start -= rate * interval;
+        }
       }
 
       elapse = timestamp - start;
@@ -3605,11 +3616,16 @@ function createInterval(callback, interval, progress) {
       _pause = true;
       start = 0;
     },
-    play: function play() {
+    play: function play(reset) {
       start = 0;
 
       if (_pause) {
         _pause = false;
+
+        if (reset) {
+          rate = 0;
+        }
+
         requestAnimationFrame(step);
       }
     }
@@ -4217,7 +4233,7 @@ var PAUSE_FLAGS = {
 
       if (!flags.length) {
         Splide.emit(name + ":play");
-        interval.play();
+        interval.play(Splide.options.resetProgress);
       }
     },
 

+ 18 - 2
dist/js/splide.js

@@ -1210,6 +1210,13 @@ var DEFAULTS = {
    */
   pauseOnFocus: true,
 
+  /**
+   * Whether to reset progress of the autoplay timer when resumed.
+   *
+   * @type {boolean}
+   */
+  resetProgress: true,
+
   /**
    * Loading images lazily.
    * Image src must be provided by a data-splide-lazy attribute.
@@ -3571,6 +3578,10 @@ function createInterval(callback, interval, progress) {
     if (!_pause) {
       if (!start) {
         start = timestamp;
+
+        if (rate && rate < 1) {
+          start -= rate * interval;
+        }
       }
 
       elapse = timestamp - start;
@@ -3595,11 +3606,16 @@ function createInterval(callback, interval, progress) {
       _pause = true;
       start = 0;
     },
-    play: function play() {
+    play: function play(reset) {
       start = 0;
 
       if (_pause) {
         _pause = false;
+
+        if (reset) {
+          rate = 0;
+        }
+
         requestAnimationFrame(step);
       }
     }
@@ -4207,7 +4223,7 @@ var PAUSE_FLAGS = {
 
       if (!flags.length) {
         Splide.emit(name + ":play");
-        interval.play();
+        interval.play(Splide.options.resetProgress);
       }
     },
 

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
dist/js/splide.min.js


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


+ 1 - 1
src/js/components/autoplay/index.js

@@ -93,7 +93,7 @@ export default ( Splide, Components, name ) => {
 
 			if ( ! flags.length ) {
 				Splide.emit( `${ name }:play` );
-				interval.play();
+				interval.play( Splide.options.resetProgress );
 			}
 		},
 

+ 7 - 0
src/js/constants/defaults.js

@@ -191,6 +191,13 @@ export const DEFAULTS = {
 	 */
 	pauseOnFocus: true,
 
+	/**
+	 * Whether to reset progress of the autoplay timer when resumed.
+	 *
+	 * @type {boolean}
+	 */
+	resetProgress: true,
+
 	/**
 	 * Loading images lazily.
 	 * Image src must be provided by a data-splide-lazy attribute.

+ 10 - 1
src/js/utils/time.js

@@ -44,6 +44,10 @@ export function createInterval( callback, interval, progress ) {
 		if ( ! pause ) {
 			if ( ! start ) {
 				start = timestamp;
+
+				if ( rate && rate < 1 ) {
+					start -= rate * interval;
+				}
 			}
 
 			elapse = timestamp - start;
@@ -69,11 +73,16 @@ export function createInterval( callback, interval, progress ) {
 			start = 0;
 		},
 
-		play() {
+		play( reset ) {
 			start = 0;
 
 			if ( pause ) {
 				pause = false;
+
+				if ( reset ) {
+					rate = 0;
+				}
+
 				requestAnimationFrame( step );
 			}
 		},

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio