我是靠谱客的博主 漂亮鸡,这篇文章主要介绍直播app开发,滑动式的顶部导航栏(左右横向滑动),现在分享给大家,希望可以做个参考。

直播app开发,滑动式的顶部导航栏(左右横向滑动)效果实现的相关代码

复制代码
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<template> <view class="container"> <view class="status_bar" v-bind:style="{ height: statusBarHeight }"></view> <!-- <view class="navbar"> <view :class="[tabindex==1?'navbtn':'navactive']" @click="switchtabar(1)">接单任务</view> <view :class="[tabindex==2?'navbtn':'navactive']" @click="switchtabar(2)">套餐任务</view> <view :class="[tabindex==3?'navbtn':'navactive']" @click="switchtabar(3)">接单记录</view> </view> --> <view class="uni-tab-bar"> <scroll-view id="tab-bar" class="uni-swiper-tab" scroll-x :scroll-left="scrollLeft"> <view v-for="(tab,index) in tabBars" :key="tab.id" :class="['swiper-tab-list',tabIndex==index ? 'active' : '']" :id="tab.id" :data-current="index" @click="tapTab(index)">{{tab.name}}</view> </scroll-view> <swiper :current="tabIndex" class="swiper-box" duration="300" @change="changeTab"> <swiper-item v-for="(tab,index1) in newsitems" :key="index1"> {{tab.name}} </swiper-item> </swiper> </view> </view> </template> <script> import { mapGetters, mapActions } from 'vuex'; import util from '../../static/js/util.js'; import regex from '../../static/js/regex.js'; export default { computed: { ...mapGetters(['statusBarHeight']) }, data() { return { pay: {}, status: '', paylists: {}, payname: uni.getStorageSync('paylist').pay_type_name, payid: uni.getStorageSync('paylist').id, tabindex:1, newsitems:[{ name: '关注', id: 'guanzhu' }, { name: '推荐', id: 'tuijian' }, { name: '体育', id: 'tiyu' }, { name: '热点', id: 'redian' }, { name: '财经', id: 'caijing' }, { name: '娱乐', id: 'yule' }, { name: '军事', id: 'junshi' }, { name: '历史', id: 'lishi' }, { name: '本地', id: 'bendi' }], tabBars: [{ name: '关注', id: 'guanzhu' }, { name: '推荐', id: 'tuijian' }, { name: '体育', id: 'tiyu' }, { name: '热点', id: 'redian' }, { name: '财经', id: 'caijing' }, { name: '娱乐', id: 'yule' }, { name: '军事', id: 'junshi' }, { name: '历史', id: 'lishi' }, { name: '本地', id: 'bendi' }], scrollLeft: 0, isClickChange: false, tabIndex: 0, }; }, onLoad: function(e) { this.pay = uni.getStorageSync('paylist'); }, methods: { async changeTab(e) { let index = e.detail.current; if (this.isClickChange) { this.tabIndex = index; this.isClickChange = false; return; } let tabBar = await this.getElSize("tab-bar"), tabBarScrollLeft = tabBar.scrollLeft; let width = 0; for (let i = 0; i < index; i++) { let result = await this.getElSize(this.tabBars[i].id); width += result.width; } let winWidth = uni.getSystemInfoSync().windowWidth, nowElement = await this.getElSize(this.tabBars[index].id), nowWidth = nowElement.width; if (width + nowWidth - tabBarScrollLeft > winWidth) { this.scrollLeft = width + nowWidth - winWidth; } if (width < tabBarScrollLeft) { this.scrollLeft = width; } this.isClickChange = false; this.tabIndex = index; //一旦访问data就会出问题 }, async tapTab(index) { //点击tab-bar console.log(index); if (this.tabIndex === index) { return false; } else { let tabBar = await this.getElSize("tab-bar"), tabBarScrollLeft = tabBar.scrollLeft; //点击的时候记录并设置scrollLeft this.scrollLeft = tabBarScrollLeft; this.isClickChange = true; this.tabIndex = index; } }, switchtabar(index){ this.tabindex=index; }, getElSize(id) { //得到元素的size return new Promise((res, rej) => { uni.createSelectorQuery().select('#' + id).fields({ size: true, scrollOffset: true }, (data) => { res(data); }).exec(); }); }, golist() { uni.navigateTo({ url: '/pages/c2c/selloutlist' }); }, goerwei() { uni.navigateTo({ url: '/pages/c2c/opay?pay=1' }); } } }; </script> <style lang="scss" scoped> .container { width: 100%; font-size: 28upx; background: #f2f2f2; color: #555; height: 100vh; overflow: scroll; position: absolute; font-weight: 400; font-family: '仿宋'; text-align: center; .navbar{ width: 100%; font-size: 28upx; background: #fff; color: #000; height: 90upx; .navbtn{ width:33%; float:left; line-height: 90upx; font-size:36px; border-bottom:5upx solid #E6BE7D; } .navactive{ width:33%; float:left; line-height: 90upx; font-size:28px; border-bottom:5upx solid #fff; color:#ccc; } } } </style>

以上就是直播app开发,滑动式的顶部导航栏(左右横向滑动)效果实现的相关代码, 更多内容欢迎关注之后的文章

最后

以上就是漂亮鸡最近收集整理的关于直播app开发,滑动式的顶部导航栏(左右横向滑动)的全部内容,更多相关直播app开发,滑动式内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部