From c82e86bc4b35819fc6730e11c34e7d09121cde3e Mon Sep 17 00:00:00 2001 From: hyrious Date: Wed, 15 Jun 2022 09:37:29 +0800 Subject: [PATCH] fix `autoSpacing` to take effect after DOM ready --- js/heti-addon.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/heti-addon.js b/js/heti-addon.js index 8307523..afd8276 100644 --- a/js/heti-addon.js +++ b/js/heti-addon.js @@ -118,13 +118,15 @@ class Heti { } autoSpacing () { - document.addEventListener('DOMContentLoaded', () => { + const callback = () => { const $$rootList = document.querySelectorAll(this.rootSelector) for (let $$root of $$rootList) { this.spacingElement($$root) } - }) + } + if (document.readyState === 'complete') setTimeout(callback) + else document.addEventListener('DOMContentLoaded', callback) } }