[bugfix] NoticeBar text disappeared when page back (#280)

* [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

* [bugfix] Swipe width calc error

* [Doc] english document of all action components

* [Doc] change document site path to /zanui/vant

* [Doc] fix

* [bugfix] uploader style error

* [bugfix] tabs document demo

* [new feature] Cell support vue-router target route

* [bugfix] add cell test cases

* update yarn.lock

* [bugfix] Tabbar cann't display info when use icon slot

* [Doc] update document title

* [bugfix] Dialog should reset button text when showed

* [new feature] CouponList add showCloseButton prop

* [new feature] Swipe add 'initialSwipe' prop

* [bugfix] NoticeBar text disappeared when page back
This commit is contained in:
neverland 2017-11-03 07:13:18 -05:00 committed by GitHub
parent 74a3eea203
commit 3f7985ed2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 18 deletions

View File

@ -21,6 +21,7 @@ Vue.component(NoticeBar.name, NoticeBar);
:::demo 基础用法 :::demo 基础用法
```html ```html
<van-notice-bar text="测试测试。"></van-notice-bar>
<van-notice-bar <van-notice-bar
text="足协杯战线连续第2年上演广州德比战上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。" text="足协杯战线连续第2年上演广州德比战上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。"
left-icon="//img.yzcdn.cn/public_files/2017/8/10/6af5b7168eed548100d9041f07b7c616.png" left-icon="//img.yzcdn.cn/public_files/2017/8/10/6af5b7168eed548100d9041f07b7c616.png"

View File

@ -9,7 +9,12 @@
<img :src="leftIcon" /> <img :src="leftIcon" />
</div> </div>
<div class="van-notice-bar__content-wrap" ref="contentWrap"> <div class="van-notice-bar__content-wrap" ref="contentWrap">
<div class="van-notice-bar__content" ref="content" :style="contentStyle" @transitionend="onTransitionEnd"> <div
ref="content"
:class="['van-notice-bar__content', animationClass]"
:style="contentStyle"
@animationend="onAnimationEnd"
>
<slot>{{ text }}</slot> <slot>{{ text }}</slot>
</div> </div>
</div> </div>
@ -55,11 +60,12 @@ export default {
data() { data() {
return { return {
wrapWidth: 0,
firstRound: true, firstRound: true,
duration: 0, duration: 0,
offsetWidth: 0, offsetWidth: 0,
showNoticeBar: true, showNoticeBar: true,
diableTransition: false animationClass: ''
}; };
}, },
@ -75,9 +81,9 @@ export default {
}, },
contentStyle() { contentStyle() {
return { return {
transform: `translate3d(${-this.offsetWidth}px, 0, 0)`, paddingLeft: this.firstRound ? 0 : this.wrapWidth + 'px',
transitionDelay: (this.firstRound ? this.delay : 0) + 's', animationDelay: (this.firstRound ? this.delay : 0) + 's',
transitionDuration: this.duration + 's' animationDuration: this.duration + 's'
}; };
} }
}, },
@ -88,7 +94,8 @@ export default {
if (this.scrollable && offsetWidth > wrapWidth) { if (this.scrollable && offsetWidth > wrapWidth) {
this.wrapWidth = wrapWidth; this.wrapWidth = wrapWidth;
this.offsetWidth = offsetWidth; this.offsetWidth = offsetWidth;
this.duration = (offsetWidth + wrapWidth) / this.speed; this.duration = offsetWidth / this.speed;
this.animationClass = 'van-notice-bar__play';
} }
}, },
@ -96,17 +103,12 @@ export default {
onClickIcon() { onClickIcon() {
this.showNoticeBar = this.mode !== 'closeable'; this.showNoticeBar = this.mode !== 'closeable';
}, },
onTransitionEnd() { onAnimationEnd() {
const { offsetWidth, wrapWidth } = this;
this.firstRound = false; this.firstRound = false;
this.duration = 0; this.$nextTick(() => {
this.offsetWidth = -this.wrapWidth; this.duration = (this.offsetWidth + this.wrapWidth) / this.speed;
this.animationClass = 'van-notice-bar__play--infinite';
// wait for vue render && dom update });
setTimeout(() => {
this.duration = (offsetWidth + 2 * wrapWidth) / this.speed;
this.offsetWidth = offsetWidth;
}, 50);
} }
} }
}; };

View File

@ -32,7 +32,6 @@
position: absolute; position: absolute;
font-size: 15px; font-size: 15px;
line-height: 1; line-height: 1;
cursor: pointer;
} }
&__content-wrap { &__content-wrap {
@ -45,6 +44,24 @@
&__content { &__content {
position: absolute; position: absolute;
white-space: nowrap; white-space: nowrap;
transition: all linear; }
&__play {
animation: van-notice-bar-play linear both;
}
&__play--infinite {
animation: van-notice-bar-play-infinite linear infinite both;
} }
} }
/**
* Declare two same keyframes
* In case that some mobile browsers can continue animation when className changed
*/
@keyframes van-notice-bar-play {
to { transform: translate3d(-100%, 0, 0) }
}
@keyframes van-notice-bar-play-infinite {
to { transform: translate3d(-100%, 0, 0) }
}