From 3c12a426ca68aa113783268b09420a5b9f83a35b Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 26 Oct 2017 02:37:14 -0500 Subject: [PATCH] [new feature] Notice bar support more props (#254) * [bugfix] CouponList always show empty info * [bugfix] add click feedback of buttons in components * [Doc] add custom theme document * [new feature] Notice bar support more props * [bugfix] PullRefresh test cases * [bugfix] unused NoticeBar style --- docs/examples-docs/en-US/notice-bar.md | 11 +++++-- docs/examples-docs/zh-CN/notice-bar.md | 10 +++++-- packages/notice-bar/index.vue | 40 +++++++++++++++++++------- packages/pull-refresh/index.vue | 8 ++++-- packages/vant-css/src/notice-bar.css | 19 ++++++++++-- test/unit/specs/pull-refresh.spec.js | 4 +-- 6 files changed, 72 insertions(+), 20 deletions(-) diff --git a/docs/examples-docs/en-US/notice-bar.md b/docs/examples-docs/en-US/notice-bar.md index 5b8d9fc69..a8511ede1 100644 --- a/docs/examples-docs/en-US/notice-bar.md +++ b/docs/examples-docs/en-US/notice-bar.md @@ -13,7 +13,10 @@ Vue.component(NoticeBar.name, NoticeBar); :::demo Basic Usage ```html - + ``` ::: @@ -47,8 +50,12 @@ Vue.component(NoticeBar.name, NoticeBar); |-----------|-----------|-----------|-------------|-------------| | mode | Mode | String | `''` | `closeable` `link` | | delay | Animation delay (s) | Number | `1` | - | -| speed | Scroll speed (px) | Number | `40` | - | +| speed | Scroll speed (px) | Number | `50` | - | | scrollable | Whether to scroll content | Boolean | `true` | - | +| leftIcon | Image url of left icon | String | - | - | +| color | Text color | String | `#f60` | - | +| background | Background color | String | `#fff7cc` | - | + ### Event diff --git a/docs/examples-docs/zh-CN/notice-bar.md b/docs/examples-docs/zh-CN/notice-bar.md index 2d2542fbd..b41b06cee 100644 --- a/docs/examples-docs/zh-CN/notice-bar.md +++ b/docs/examples-docs/zh-CN/notice-bar.md @@ -21,7 +21,10 @@ Vue.component(NoticeBar.name, NoticeBar); :::demo 基础用法 ```html - + ``` ::: @@ -59,8 +62,11 @@ Vue.component(NoticeBar.name, NoticeBar); |-----------|-----------|-----------|-------------|-------------| | mode | 通告栏模式 | String | `''` | `closeable` `link` | | delay | 动画延迟时间,单位秒 | Number | `1` | - | -| speed | 滚动速率,单位px | Number | `40` | - | +| speed | 滚动速率,单位px | Number | `50` | - | | scrollable | 是否滚动 | Boolean | `true` | - | +| leftIcon | 左侧图标图片链接 | String | - | - | +| color | 文本颜色 | String | `#f60` | - | +| background | 滚动条背景 | String | `#fff7cc` | - | ### Event diff --git a/packages/notice-bar/index.vue b/packages/notice-bar/index.vue index 3513e55ba..bc3d9667b 100644 --- a/packages/notice-bar/index.vue +++ b/packages/notice-bar/index.vue @@ -1,11 +1,19 @@ @@ -23,6 +31,9 @@ export default { props: { text: String, + leftIcon: String, + color: String, + background: String, mode: { type: String, default: '', @@ -38,12 +49,13 @@ export default { }, speed: { type: Number, - default: 40 + default: 50 } }, data() { return { + firstRound: true, duration: 0, offsetWidth: 0, showNoticeBar: true, @@ -55,12 +67,17 @@ export default { iconName() { return this.mode === 'closeable' ? 'close' : this.mode === 'link' ? 'arrow' : ''; }, + barStyle() { + return { + color: this.color, + background: this.background + }; + }, contentStyle() { return { transform: `translate3d(${-this.offsetWidth}px, 0, 0)`, - transitionDelay: this.delay + 's', - transitionDuration: this.duration + 's', - transitionProperty: this.diableTransition ? 'none' : 'all' + transitionDelay: (this.firstRound ? this.delay : 0) + 's', + transitionDuration: this.duration + 's' }; } }, @@ -69,6 +86,7 @@ export default { const offsetWidth = this.$refs.content.getBoundingClientRect().width; const wrapWidth = this.$refs.contentWrap.getBoundingClientRect().width; if (this.scrollable && offsetWidth > wrapWidth) { + this.wrapWidth = wrapWidth; this.offsetWidth = offsetWidth; this.duration = (offsetWidth + wrapWidth) / this.speed; } @@ -79,12 +97,14 @@ export default { this.showNoticeBar = this.mode !== 'closeable'; }, onTransitionEnd() { - const { offsetWidth } = this; - this.diableTransition = true; - this.offsetWidth = 0; + const { offsetWidth, wrapWidth } = this; + this.firstRound = false; + this.duration = 0; + this.offsetWidth = -this.wrapWidth; + // wait for vue render && dom update setTimeout(() => { - this.diableTransition = false; + this.duration = (offsetWidth + 2 * wrapWidth) / this.speed; this.offsetWidth = offsetWidth; }, 50); } diff --git a/packages/pull-refresh/index.vue b/packages/pull-refresh/index.vue index 8840e8a66..2cba3db7d 100644 --- a/packages/pull-refresh/index.vue +++ b/packages/pull-refresh/index.vue @@ -28,7 +28,7 @@