[bug fix] NoticeBar: 属性text为动态数据且使用:text方式使用时,添加自动滚动 (#515)

This commit is contained in:
xujian 2018-01-06 23:06:15 +08:00 committed by neverland
parent 7a86fb69bb
commit beee252205

View File

@ -82,13 +82,12 @@ export default create({
},
mounted() {
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 / this.speed;
this.animationClass = 'van-notice-bar__play';
this.initAnimation();
},
watch: {
text: function() {
this.$nextTick(this.initAnimation);
}
},
@ -102,6 +101,16 @@ export default create({
this.duration = (this.offsetWidth + this.wrapWidth) / this.speed;
this.animationClass = 'van-notice-bar__play--infinite';
});
},
initAnimation() {
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 / this.speed;
this.animationClass = 'van-notice-bar__play';
}
}
}
});