fix(NoticeBar): replay event only triggered once (#6293)
This commit is contained in:
+26
-24
@@ -1,4 +1,5 @@
|
||||
import { createNamespace } from '../utils';
|
||||
import { doubleRaf } from '../utils/dom/raf';
|
||||
import Icon from '../icon';
|
||||
|
||||
const [createComponent, bem] = createNamespace('notice-bar');
|
||||
@@ -27,12 +28,12 @@ export default createComponent({
|
||||
|
||||
data() {
|
||||
return {
|
||||
show: true,
|
||||
offset: 0,
|
||||
duration: 0,
|
||||
wrapWidth: 0,
|
||||
firstRound: true,
|
||||
duration: 0,
|
||||
offsetWidth: 0,
|
||||
showNoticeBar: true,
|
||||
animationClass: '',
|
||||
contentWidth: 0,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -47,25 +48,27 @@ export default createComponent({
|
||||
methods: {
|
||||
onClickIcon(event) {
|
||||
if (this.mode === 'closeable') {
|
||||
this.showNoticeBar = false;
|
||||
this.show = false;
|
||||
this.$emit('close', event);
|
||||
}
|
||||
},
|
||||
|
||||
onAnimationEnd() {
|
||||
onTransitionEnd() {
|
||||
this.offset = this.wrapWidth;
|
||||
this.duration = 0;
|
||||
this.firstRound = false;
|
||||
this.$nextTick(() => {
|
||||
this.duration = (this.offsetWidth + this.wrapWidth) / this.speed;
|
||||
this.animationClass = bem('play--infinite');
|
||||
|
||||
doubleRaf(() => {
|
||||
this.offset = -this.contentWidth;
|
||||
this.duration = (this.contentWidth + this.wrapWidth) / this.speed;
|
||||
this.$emit('replay');
|
||||
});
|
||||
},
|
||||
|
||||
reset() {
|
||||
this.wrapWidth = 0;
|
||||
this.offsetWidth = 0;
|
||||
this.animationClass = '';
|
||||
this.duration = 0;
|
||||
this.wrapWidth = 0;
|
||||
this.contentWidth = 0;
|
||||
},
|
||||
|
||||
start() {
|
||||
@@ -76,12 +79,13 @@ export default createComponent({
|
||||
}
|
||||
|
||||
const wrapWidth = wrap.getBoundingClientRect().width;
|
||||
const offsetWidth = content.getBoundingClientRect().width;
|
||||
if (this.scrollable && offsetWidth > wrapWidth) {
|
||||
const contentWidth = content.getBoundingClientRect().width;
|
||||
|
||||
if (this.scrollable && contentWidth > wrapWidth) {
|
||||
this.offset = -contentWidth;
|
||||
this.duration = contentWidth / this.speed;
|
||||
this.wrapWidth = wrapWidth;
|
||||
this.offsetWidth = offsetWidth;
|
||||
this.duration = offsetWidth / this.speed;
|
||||
this.animationClass = bem('play');
|
||||
this.contentWidth = contentWidth;
|
||||
} else {
|
||||
this.reset();
|
||||
}
|
||||
@@ -98,9 +102,9 @@ export default createComponent({
|
||||
};
|
||||
|
||||
const contentStyle = {
|
||||
paddingLeft: this.firstRound ? 0 : this.wrapWidth + 'px',
|
||||
animationDelay: (this.firstRound ? this.delay : 0) + 's',
|
||||
animationDuration: this.duration + 's',
|
||||
transform: `translateX(${this.offset}px)`,
|
||||
transitionDelay: (this.firstRound ? this.delay : 0) + 's',
|
||||
transitionDuration: this.duration + 's',
|
||||
};
|
||||
|
||||
function LeftIcon() {
|
||||
@@ -143,7 +147,7 @@ export default createComponent({
|
||||
return (
|
||||
<div
|
||||
role="alert"
|
||||
vShow={this.showNoticeBar}
|
||||
vShow={this.show}
|
||||
class={bem({ wrapable: this.wrapable })}
|
||||
style={barStyle}
|
||||
onClick={(event) => {
|
||||
@@ -156,12 +160,10 @@ export default createComponent({
|
||||
ref="content"
|
||||
class={[
|
||||
bem('content'),
|
||||
this.animationClass,
|
||||
{ 'van-ellipsis': !this.scrollable && !this.wrapable },
|
||||
]}
|
||||
style={contentStyle}
|
||||
onAnimationend={this.onAnimationEnd}
|
||||
onWebkitAnimationEnd={this.onAnimationEnd}
|
||||
onTransitionend={this.onTransitionEnd}
|
||||
>
|
||||
{this.slots() || this.text}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user