neverland 83f9654681
[Improvement] optimize staticClass (#337)
* fix: Tabbar icon line-height

* [new feature] progress add showPivot prop

* [new feature] TabItem support vue-router

* [new feature] update document header style

* [Doc] add toast english ducoment

* [bugfix] Search box-sizing wrong

* [Doc] update vant-demo respo

* [Doc] translate theme & demo pages

* [Doc] add Internationalization document

* [bugfix] remove unnecessary props

* [fix] optimize clickoutside

* [new feature] optimize find-parent

* [new feature]: change document title accordinng to language

* [new feature] Pagination code review

* [improvement] adjust icon-font unicode

* [improvement] Icon spinner color inherit

* [improvement] icon default width

* [bugfix] DateTimePicker validate date props

* [bugfix] Tab item text ellipsis

* [improvement] optimize single line ellipsis

* [Improvement] optimzie staticClass
2017-11-22 10:51:01 +08:00

112 lines
2.5 KiB
Vue

<template>
<div
v-show="showNoticeBar"
class="van-notice-bar"
:class="{ 'van-notice-bar--withicon': mode }"
:style="barStyle"
@click="$emit('click')"
>
<div class="van-notice-bar__left-icon" v-if="leftIcon">
<img :src="leftIcon" />
</div>
<div class="van-notice-bar__content-wrap" ref="contentWrap">
<div
ref="content"
class="van-notice-bar__content"
:class="animationClass"
:style="contentStyle"
@animationend="onAnimationEnd"
>
<slot>{{ text }}</slot>
</div>
</div>
<van-icon class="van-notice-bar__right-icon" :name="iconName" v-if="iconName" @click="onClickIcon" />
</div>
</template>
<script>
import Icon from '../icon';
export default {
name: 'van-notice-bar',
components: {
[Icon.name]: Icon
},
props: {
text: String,
mode: String,
color: String,
leftIcon: String,
background: String,
delay: {
type: [String, Number],
default: 1
},
scrollable: {
type: Boolean,
default: true
},
speed: {
type: Number,
default: 50
}
},
data() {
return {
wrapWidth: 0,
firstRound: true,
duration: 0,
offsetWidth: 0,
showNoticeBar: true,
animationClass: ''
};
},
computed: {
iconName() {
return this.mode === 'closeable' ? 'close' : this.mode === 'link' ? 'arrow' : '';
},
barStyle() {
return {
color: this.color,
background: this.background
};
},
contentStyle() {
return {
paddingLeft: this.firstRound ? 0 : this.wrapWidth + 'px',
animationDelay: (this.firstRound ? this.delay : 0) + 's',
animationDuration: this.duration + 's'
};
}
},
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';
}
},
methods: {
onClickIcon() {
this.showNoticeBar = this.mode !== 'closeable';
},
onAnimationEnd() {
this.firstRound = false;
this.$nextTick(() => {
this.duration = (this.offsetWidth + this.wrapWidth) / this.speed;
this.animationClass = 'van-notice-bar__play--infinite';
});
}
}
};
</script>