Wait for full animation preview duration
This commit is contained in:
1 parent
b5301f3f16
commit
8ee59e97d3
3 files changed
+22
-4
No files matched your search
@@ -132,6 +132,17 @@ export function createSlideAnimationEditor(options) {
|
||||
function getPreviewElements() {
|
||||
return Array.prototype.slice.call(previewHost.querySelectorAll('.slide-preview-region[data-region-key]'));
|
||||
}
|
||||
function getAnimationDurationMs(element, fallbackDurationMs) {
|
||||
if (typeof window.getComputedStyle !== 'function') return fallbackDurationMs;
|
||||
var durations = String(window.getComputedStyle(element).animationDuration || '').split(',');
|
||||
var longestDuration = durations.reduce(function (longest, value) {
|
||||
var match = value.trim().match(/^([\d.]+)\s*(ms|s)$/i);
|
||||
if (!match) return longest;
|
||||
var duration = Number(match[1]) * (match[2].toLowerCase() === 's' ? 1000 : 1);
|
||||
return Number.isFinite(duration) ? Math.max(longest, duration) : longest;
|
||||
}, 0);
|
||||
return longestDuration || fallbackDurationMs;
|
||||
}
|
||||
function stopPreview() {
|
||||
if (previewTimer) window.clearTimeout(previewTimer);
|
||||
previewTimer = 0;
|
||||
@@ -185,7 +196,7 @@ export function createSlideAnimationEditor(options) {
|
||||
void element.offsetWidth;
|
||||
element.classList.add('animate__animated', 'animate__' + preset);
|
||||
if (mode === 'loop') element.classList.add('animate__repeat-1');
|
||||
longest = Math.max(longest, delay + duration * iterations);
|
||||
longest = Math.max(longest, delay + getAnimationDurationMs(element, duration) * iterations);
|
||||
});
|
||||
updatePreviewButtons();
|
||||
previewTimer = window.setTimeout(function () {
|
||||
|
||||
Reference in new issue
Block a user