Blame view

components/thorui/tui-banner-arc/tui-banner-arc.vue 1.26 KB
46b6767c   刘淇   init 提交到库
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
  <template>
  	<view class="tui-banner-arc" :style="{height:height+'rpx'}">
  		<view class="tui-banner--box"
  			:style="{background:background,height:height+'rpx',width:width+'%',paddingLeft:(width-100)/2+'%',paddingRight:(width-100)/2+'%',left:'-'+(width-100)/2+'%'}">
  			<slot></slot>
  		</view>
  	</view>
  </template>
  
  <script>
  	export default {
  		name: "tui-banner-arc",
  		// #ifdef MP-WEIXIN
  		options: {
  			virtualHost: true
  		},
  		// #endif
  		props: {
  			height: {
  				type: [Number, String],
  				default: 400
  			},
  			percent: {
  				type: [Number, String],
  				default: 120
  			},
  			background: {
  				type: String,
  				default: ''
  			}
  		},
  		created() {
  			this.width = this.getPercent(this.percent)
  		},
  		watch: {
  			percent(val) {
  				this.width = this.getPercent(val)
  			}
  		},
  		data() {
  			return {
  				width: 120
  			};
  		},
  		methods: {
  			getPercent(val) {
  				//最低值120,尽量传偶数值
  				val = Number(val || 0)
  				return val < 120 ? 120 : val
  			}
  		},
  	}
  </script>
  
  <style scoped>
  	.tui-banner-arc {
  		width: 100%;
  		position: relative;
  		flex-direction: column;
  		align-items: center;
  		overflow: hidden;
  	}
  
  	.tui-banner--box {
  		box-sizing: border-box;
  		position: absolute;
  		z-index: 1;
  		top: 0;
  		border-radius: 0 0 50% 50%;
  		overflow: hidden;
  	}
  </style>