diff --git a/docs/examples-docs/zh-CN/notice-bar.md b/docs/examples-docs/zh-CN/notice-bar.md
index b41b06cee..4eaeccbfb 100644
--- a/docs/examples-docs/zh-CN/notice-bar.md
+++ b/docs/examples-docs/zh-CN/notice-bar.md
@@ -21,6 +21,7 @@ Vue.component(NoticeBar.name, NoticeBar);
:::demo 基础用法
```html
+
-
@@ -55,11 +60,12 @@ export default {
data() {
return {
+ wrapWidth: 0,
firstRound: true,
duration: 0,
offsetWidth: 0,
showNoticeBar: true,
- diableTransition: false
+ animationClass: ''
};
},
@@ -75,9 +81,9 @@ export default {
},
contentStyle() {
return {
- transform: `translate3d(${-this.offsetWidth}px, 0, 0)`,
- transitionDelay: (this.firstRound ? this.delay : 0) + 's',
- transitionDuration: this.duration + 's'
+ paddingLeft: this.firstRound ? 0 : this.wrapWidth + 'px',
+ animationDelay: (this.firstRound ? this.delay : 0) + 's',
+ animationDuration: this.duration + 's'
};
}
},
@@ -88,7 +94,8 @@ export default {
if (this.scrollable && offsetWidth > wrapWidth) {
this.wrapWidth = wrapWidth;
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() {
this.showNoticeBar = this.mode !== 'closeable';
},
- onTransitionEnd() {
- const { offsetWidth, wrapWidth } = this;
+ onAnimationEnd() {
this.firstRound = false;
- this.duration = 0;
- this.offsetWidth = -this.wrapWidth;
-
- // wait for vue render && dom update
- setTimeout(() => {
- this.duration = (offsetWidth + 2 * wrapWidth) / this.speed;
- this.offsetWidth = offsetWidth;
- }, 50);
+ this.$nextTick(() => {
+ this.duration = (this.offsetWidth + this.wrapWidth) / this.speed;
+ this.animationClass = 'van-notice-bar__play--infinite';
+ });
}
}
};
diff --git a/packages/vant-css/src/notice-bar.css b/packages/vant-css/src/notice-bar.css
index 8d0da9a7e..35436facb 100644
--- a/packages/vant-css/src/notice-bar.css
+++ b/packages/vant-css/src/notice-bar.css
@@ -32,7 +32,6 @@
position: absolute;
font-size: 15px;
line-height: 1;
- cursor: pointer;
}
&__content-wrap {
@@ -45,6 +44,24 @@
&__content {
position: absolute;
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) }
+}