-
Notifications
You must be signed in to change notification settings - Fork 0
/
marquee.vue
109 lines (99 loc) · 3.61 KB
/
marquee.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<template>
<div class="marquee">
<div class="title">
<div class="tit_content" ref="wrap">
<!--<p>测试数据测试数据测试数据测试数据测</p>-->
<p ref="titWidth" :class='animationClass' :style="contentStyle">{{content}}</p>
</div>
</div>
</div>
</template>
<script>
export default {
name: "marquee",
data() {
return {
content: String,
delay:'',
speed:0.02,//为了过渡,已经运动速度相等,我们用px/s,即每px需要多少秒,暂定每px需要0.02s
duration: 0,
animationClass: '',
contentStyle:{},
first:true,
}
},
created() {
this.content = '测试数据测试数据测试数据测试数据测测试数据测测试数据测测试数据测试数据测测试数据测测试数据测';
},
methods: {},
mounted() {
this.$nextTick(() => {
const {wrap, titWidth} = this.$refs;
if (!wrap || !titWidth) {
return;
}
const wrapWidth = wrap.getBoundingClientRect().width;
/* const paddingLeft =((screen.width - wrapWidth) / 2 + wrapWidth);
console.log(paddingLeft);*/
const offsetWidth = titWidth.getBoundingClientRect().width;
this.delay = offsetWidth * this.speed *1000 ;
if (offsetWidth>wrapWidth){
this.animationClass ='tit_content__play';
this.contentStyle = {
animationDelay:0 ,//延时
animationDuration:offsetWidth * this.speed +'s',
};
}
setTimeout(()=>{
this.animationClass ='tit_content--infinite ';
this.contentStyle = {
animationDelay:0 ,//延时
animationDuration: (wrapWidth+offsetWidth) *this.speed +'s' ,//总时间
paddingLeft:wrapWidth +'px'
};
}, this.delay)
})
}
}
</script>
<style scoped lang="less">
@width: 100%;
.title {
width: @width;
height: 0.9rem;
background: linear-gradient(0deg, #C2F4BE 0%, #ECFFDE 100%);
padding: 0 .5rem;
box-sizing: border-box;
font-size: 0.3rem;
.tit_content {
overflow: hidden;
height: 0.9rem;
line-height: 0.9rem;
position: relative;
p {
white-space: nowrap;
word-wrap: normal;
display: inline-block;
position: absolute;
}
&__play {
animation-name: van-notice-bar-play ;
animation-iteration-count:1;
animation-fill-mode:both;
animation-timing-function: linear;
}
&--infinite {
animation-name: van-notice-bar-play-infinite ;
animation-iteration-count:infinite;
animation-fill-mode:both;
animation-timing-function: linear;
}
}
}
@keyframes van-notice-bar-play {
to { transform: translate3d(-100%, 0, 0); }
}
@keyframes van-notice-bar-play-infinite {
to { transform: translate3d(-100%, 0, 0); }
}
</style>