Skip to content

Commit bcd128c

Browse files
Needs to update arrows while moving.
1 parent 9878492 commit bcd128c

10 files changed

+88
-24
lines changed

dist/js/splide-extension-auto-scroll.cjs.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* @splidejs/splide-extension-auto-scroll
3-
* Version : 0.5.2
3+
* Version : 0.5.3
44
* License : MIT
55
* Copyright: 2022 Naotoshi Fujita
66
*/
@@ -246,6 +246,22 @@ function RequestInterval(interval, onInterval, onUpdate, limit) {
246246
isPaused: isPaused
247247
};
248248
}
249+
250+
function Throttle(func, duration) {
251+
var interval;
252+
253+
function throttled() {
254+
if (!interval) {
255+
interval = RequestInterval(duration || 0, function () {
256+
func();
257+
interval = null;
258+
}, null, 1);
259+
interval.start();
260+
}
261+
}
262+
263+
return throttled;
264+
}
249265
var CLASS_ACTIVE = "is-active";
250266

251267
var SLIDE = "slide";
@@ -366,6 +382,7 @@ function AutoScroll(Splide2, Components2, options) {
366382
const { toggle } = Components2.Elements;
367383
const { Live } = Components2;
368384
const { root } = Splide2;
385+
const throttledUpdateArrows = Throttle(Components2.Arrows.update, 500);
369386
let autoScrollOptions = {};
370387
let interval;
371388
let stopped;
@@ -477,9 +494,10 @@ function AutoScroll(Splide2, Components2, options) {
477494
} else {
478495
pause(false);
479496
if (autoScrollOptions.rewind) {
480-
Splide2.go(0);
497+
Splide2.go(autoScrollOptions.speed > 0 ? 0 : Components2.Controller.getEnd());
481498
}
482499
}
500+
throttledUpdateArrows();
483501
}
484502
function computeDestination(position) {
485503
const speed = autoScrollOptions.speed || 1;

dist/js/splide-extension-auto-scroll.esm.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* @splidejs/splide-extension-auto-scroll
3-
* Version : 0.5.2
3+
* Version : 0.5.3
44
* License : MIT
55
* Copyright: 2022 Naotoshi Fujita
66
*/
@@ -242,6 +242,22 @@ function RequestInterval(interval, onInterval, onUpdate, limit) {
242242
isPaused: isPaused
243243
};
244244
}
245+
246+
function Throttle(func, duration) {
247+
var interval;
248+
249+
function throttled() {
250+
if (!interval) {
251+
interval = RequestInterval(duration || 0, function () {
252+
func();
253+
interval = null;
254+
}, null, 1);
255+
interval.start();
256+
}
257+
}
258+
259+
return throttled;
260+
}
245261
var CLASS_ACTIVE = "is-active";
246262

247263
var SLIDE = "slide";
@@ -362,6 +378,7 @@ function AutoScroll(Splide2, Components2, options) {
362378
const { toggle } = Components2.Elements;
363379
const { Live } = Components2;
364380
const { root } = Splide2;
381+
const throttledUpdateArrows = Throttle(Components2.Arrows.update, 500);
365382
let autoScrollOptions = {};
366383
let interval;
367384
let stopped;
@@ -473,9 +490,10 @@ function AutoScroll(Splide2, Components2, options) {
473490
} else {
474491
pause(false);
475492
if (autoScrollOptions.rewind) {
476-
Splide2.go(0);
493+
Splide2.go(autoScrollOptions.speed > 0 ? 0 : Components2.Controller.getEnd());
477494
}
478495
}
496+
throttledUpdateArrows();
479497
}
480498
function computeDestination(position) {
481499
const speed = autoScrollOptions.speed || 1;

dist/js/splide-extension-auto-scroll.js

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/splide-extension-auto-scroll.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/splide-extension-auto-scroll.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/types/extensions/AutoScroll/AutoScroll.d.ts.map

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splidejs/splide-extension-auto-scroll",
3-
"version": "0.5.2",
3+
"version": "0.5.3",
44
"description": "The Splide extension for continuously scrolling the slider.",
55
"author": "Naotoshi Fujita",
66
"license": "MIT",
@@ -30,7 +30,7 @@
3030
"@babel/preset-env": "^7.18.10",
3131
"@rollup/plugin-babel": "^5.3.1",
3232
"@rollup/plugin-node-resolve": "^13.3.0",
33-
"@splidejs/splide": "^4.0.11",
33+
"@splidejs/splide": "^4.0.17",
3434
"@types/jest": "^29.0.0",
3535
"@types/node": "^18.7.14",
3636
"@typescript-eslint/eslint-plugin": "^5.36.1",

src/js/extensions/AutoScroll/AutoScroll.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
FADE,
1313
Options,
1414
RequestInterval,
15+
Throttle,
1516
RequestIntervalInterface,
1617
SLIDE,
1718
Splide,
@@ -66,6 +67,11 @@ export function AutoScroll( Splide: Splide, Components: Components, options: Opt
6667
const { Live } = Components;
6768
const { root } = Splide;
6869

70+
/**
71+
* The throttled function to update arrows.
72+
*/
73+
const throttledUpdateArrows = Throttle( Components.Arrows.update, 500 );
74+
6975
/**
7076
* Keeps the latest options.
7177
*/
@@ -260,9 +266,11 @@ export function AutoScroll( Splide: Splide, Components: Components, options: Opt
260266
pause( false );
261267

262268
if ( autoScrollOptions.rewind ) {
263-
Splide.go( 0 );
269+
Splide.go( autoScrollOptions.speed > 0 ? 0 : Components.Controller.getEnd() );
264270
}
265271
}
272+
273+
throttledUpdateArrows();
266274
}
267275

268276
/**

src/js/test/php/test.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
height : 300,
1717
gap : '1rem',
1818
drag : 'free',
19-
type : 'loop',
19+
// type : 'loop',
20+
perPage: 3,
2021
autoScroll: {
2122
useToggleButton: true,
2223
// autoStart: false,
23-
// speed: -3,
24+
speed: 1,
2425
rewind: true,
2526
},
2627
reducedMotion: {
@@ -68,7 +69,7 @@
6869
<div class="splide__track">
6970
<ul class="splide__list">
7071
<?php
71-
for ( $i = 0; $i < 3; $i++ ) {
72+
for ( $i = 0; $i < 9; $i++ ) {
7273
echo '<li class="splide__slide">' . PHP_EOL;
7374
echo $i + 1;
7475
echo '</li>' . PHP_EOL;

0 commit comments

Comments
 (0)