From 16a26fa2a27cfc0d41612c4188f2798959c6b553 Mon Sep 17 00:00:00 2001 From: Lee EC Date: Wed, 9 Oct 2019 18:42:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20postmessage=20?= =?UTF-8?q?=E6=88=AA=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/index.html | 4 ++-- dist/index_demo.html | 4 ++-- info.json | 6 +++--- src/js/utils/controller.js | 27 ++++++++++++++++----------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/dist/index.html b/dist/index.html index 3787901..017e2f6 100644 --- a/dist/index.html +++ b/dist/index.html @@ -6,7 +6,7 @@ demo - +
@@ -14,5 +14,5 @@
- + \ No newline at end of file diff --git a/dist/index_demo.html b/dist/index_demo.html index 32a37b7..2e8fbd5 100644 --- a/dist/index_demo.html +++ b/dist/index_demo.html @@ -8,7 +8,7 @@ - +
@@ -18,5 +18,5 @@ - + \ No newline at end of file diff --git a/info.json b/info.json index c35e506..b05e00d 100755 --- a/info.json +++ b/info.json @@ -5,9 +5,9 @@ "title": "sina_wave", "ambName": "波浪", "github": "https://github.com/o2team-ambient/sina_wave", - "demoSnippet": "\n
\n \n
\n ", - "controlUrl": "//storage.jd.com/ambient/control-sina_wave.js?t=1570617458000", - "configUrl": "//storage.jd.com/ambient/config-sina_wave.js?t=1570617458000", + "demoSnippet": "\n
\n \n
\n ", + "controlUrl": "//storage.jd.com/ambient/control-sina_wave.js?t=1570617669000", + "configUrl": "//storage.jd.com/ambient/config-sina_wave.js?t=1570617669000", "placeholderImg": "//storage.jd.com/ambient/sina_wave_placeholder.png?t=1554260508000", "gifImg": "//storage.jd.com/ambient/sina_wave_motion.gif?t=1553781489000", "spriteImg": "//storage.jd.com/ambient/sina_wave_sprite.png?t=1554260508000" diff --git a/src/js/utils/controller.js b/src/js/utils/controller.js index 93807c6..b4bbec1 100755 --- a/src/js/utils/controller.js +++ b/src/js/utils/controller.js @@ -19,6 +19,7 @@ const isAmbientPlat = getParameterByName('platform') === '1' // 是否平台环 class Controller { ts msgTs + transMsgTs constructor () { this.config = window[O2_AMBIENT_CONFIG] || {} @@ -74,17 +75,21 @@ class Controller { // 传送数据 transMsg (dom) { - let transWin = dom.contentWindow - window[O2_AMBIENT_CONFIG].waves = window[O2_AMBIENT_CONFIG].waves.map(item => { - return { - ...item, - random: null - } - }) - transWin.postMessage({ - type: 'reset', - data: window[O2_AMBIENT_CONFIG] - }, `${window.location.protocol}${dom.getAttribute('src')}`) + if (this.transMsgTs) return + this.transMsgTs = setTimeout(() => { + this.transMsgTs = null + let transWin = dom.contentWindow + window[O2_AMBIENT_CONFIG].waves = window[O2_AMBIENT_CONFIG].waves.map(item => { + return { + ...item, + random: null + } + }) + transWin.postMessage({ + type: 'reset', + data: window[O2_AMBIENT_CONFIG] + }, `${window.location.protocol}${dom.getAttribute('src')}`) + }, 200) } // iframe dom