From 84369690c04eb3c2babc5639a5816592047dd96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=9B=E7=8B=BC?= <46393473+lang1427@users.noreply.github.com> Date: Tue, 21 Apr 2020 14:28:07 +0800 Subject: [PATCH] feat(Notice): bar reset variable and scrollable method extraction (#6069) --- src/notice-bar/index.js | 43 +++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/notice-bar/index.js b/src/notice-bar/index.js index be5b51ccf..2f258cdcf 100644 --- a/src/notice-bar/index.js +++ b/src/notice-bar/index.js @@ -39,21 +39,7 @@ export default createComponent({ watch: { text: { handler() { - this.$nextTick(() => { - const { wrap, content } = this.$refs; - if (!wrap || !content) { - return; - } - - const wrapWidth = wrap.getBoundingClientRect().width; - const offsetWidth = content.getBoundingClientRect().width; - if (this.scrollable && offsetWidth > wrapWidth) { - this.wrapWidth = wrapWidth; - this.offsetWidth = offsetWidth; - this.duration = offsetWidth / this.speed; - this.animationClass = bem('play'); - } - }); + this.start(); }, immediate: true, }, @@ -75,6 +61,33 @@ export default createComponent({ this.$emit('replay'); }); }, + + reset() { + this.wrapWidth = 0; + this.offsetWidth = 0; + this.animationClass = ''; + this.duration = 0; + }, + + start(){ + this.$nextTick(() => { + const { wrap, content } = this.$refs; + if (!wrap || !content) { + return; + } + + const wrapWidth = wrap.getBoundingClientRect().width; + const offsetWidth = content.getBoundingClientRect().width; + if (this.scrollable && offsetWidth > wrapWidth) { + this.wrapWidth = wrapWidth; + this.offsetWidth = offsetWidth; + this.duration = offsetWidth / this.speed; + this.animationClass = bem('play'); + } else { + this.reset(); + } + }); + } }, render() {