昨天看虎牙直播,发现导航栏挺有意思,自己也做个玩玩

<view class="tab_list row">
<view class="tab_item center" wx:for='{{tab_list}}' data-index="{{index}}" bindtap="tab">{{item}}</view>
<view class="border_line" style="left: {{border_left}}px; width: {{border_width}}px;"></view>
</view>
.tab_list{
position: relative
} .tab_item{
width: 20%;
height: 40px;
font-size: 14px;
} .border_line{
position: absolute;
bottom: 2px;
height: 6px;
background: linear-gradient(90deg, #FFA500, #FFD700 );
border-radius: 10px;
transition: all .2s;
}
// pages/tab/tab.js
Page({ /**
* 页面的初始数据
*/
data: {
tab_list: ['全部', '推荐', 'LOL', '户外', '一起看'],
tab_index: 0,
last_index: 0,
pos_list: [],
border_width: 16,
border_left: 0,
is_disable:false //禁止点击
}, /**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getPosition();
},
getPosition() {
let tab_index = this.data.tab_index, border_width = this.data.border_width, last_index = this.data.last_index;
let tab_width2 = border_width / 2;
let pos_list = this.data.pos_list;
if (!pos_list.length) {
const query = wx.createSelectorQuery()
query.selectAll('.tab_item').boundingClientRect()
query.exec(res => {
let { width } = res[0][0];
this.setData({
border_left: width / 2 - tab_width2,
pos_list: res[0]
})
})
} else {
let current, last;
let tab_left = pos_list[tab_index].left, tab_width = pos_list[tab_index].width;
let last_left = pos_list[last_index].left, last_width = pos_list[last_index].width;
if (tab_index < last_index) {//向左
current = tab_left + tab_width / 2 - tab_width2;
last = last_left + last_width / 2 + tab_width2;
let width = Math.abs(current - last); //当前和上次的宽度
this.setData({
border_width: width,
border_left: tab_left + tab_width / 2 - tab_width2, //向左需要动画过渡
}, () => {
setTimeout(() => {
this.setData({
border_width,
is_disable:false
})
}, 200)
})
} else { //向右
current = tab_left + tab_width / 2 + tab_width2;
last = last_left + last_width / 2 - tab_width2;
let width = Math.abs(current - last);
this.setData({
border_width: width,
}, () => {
setTimeout(() => {
this.setData({
border_width,
border_left: tab_left + tab_width / 2 - tab_width2,
is_disable: false
})
}, 300)
})
}
}
},
tab(e) {
if (this.data.is_disable) return; let index = e.currentTarget.dataset.index;
let tab_index = this.data.tab_index;
if (index != tab_index) {
this.setData({
last_index:tab_index,
tab_index: index,
is_disable:true
})
this.getPosition();
}
},
})

模仿虎牙App 导航栏切换的更多相关文章

  1. 极致精简的fragment实现导航栏切换demo

    一个小demo.用button+fragment实现导航栏切换界面,适合刚接触的新手看一下. 效果图 点击第二个后 源码: 主界面 <span style="font-size:18p ...

  2. mui底部导航栏切换分页

    使用Hbuilder的mui框架开发移动端非常便利.高效: 底部导航栏切换功能也是移动APP开发中必须实现的: 引入mui文件.下面会用到jquery,同时引进 <link href=" ...

  3. Flutter - TabBar导航栏切换后,状态丢失

    上一篇讲到了 Flutter - BottomNavigationBar底部导航栏切换后,状态丢失 里面提到了TabBar,这儿专门再写一下吧,具体怎么操作,来不让TabBar的状态丢失.毕竟大家99 ...

  4. Flutter - BottomNavigationBar底部导航栏切换后,状态丢失

    如果你用过BottomNavigationBar.TabBar.还有Drawer,你就会发现,在切换页面之后,原来的页面状态就会丢失. 要是上一页有一个数据列表,很多数据,你滚动到了下头,切换页面后, ...

  5. Flutter实战视频-移动电商-04.底部导航栏切换效果

    04.底部导航栏切换效果 博客地址: https://jspang.com/post/FlutterShop.html#toc-291 我们要做的效果图: 新建四个页面 home_page.dart ...

  6. html5 导航栏切换效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. MUI底部导航栏切换效果

    首先是html代码: <nav class="mui-bar mui-bar-tab"> <a href="view/templates/home/ho ...

  8. react-native-tab-view 导航栏切换插件讲解

    首先引入插件 yarn add react-native-tab-view 如果用的原生环境要安装另外几个插件 yarn add react-native-reanimated react-nativ ...

  9. vue 导航栏切换

    <template> <footer class="menu"> <router-link to="/" class=" ...

随机推荐

  1. Rabbitmq consumer端超时报错

    0x01 应用场景: 使用rabbitmq的exchange模式,type为direct,消费端不需要向生产端返回结果no_ack=True 其中某个consumer任务耗时较长(5min以上),结果 ...

  2. python使用信号机制实例:

    python使用信号机制实例: 程序会一直等待,直到其他程序发送CTRL-C信号给本进程.需要其他程序配合测试. 或者打开新的终端使用kill -sig PID 向一个进程发送信号,来测试. from ...

  3. redis持久化优缺点

  4. noobSTL-1-配置器-2

    noobSTL-1-配置器-2 第一级配置器 1. 功能分析 第一级配置器以malloc(),free(),realloc()等C语言函数来执行实际的内存配置. 使用C语言函数是因为C++并未直接提供 ...

  5. Swagger-ui接口文档

    参考地址 https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X#quick-annotation-overview   ...

  6. vue 实现上一周、下一周切换功能

    效果图: html 显示部分: js 显示部分: preNextBtn(val){ let _this = this; this.tableList = []; //数据重置为空 _this.show ...

  7. axios 请求中的Form Data 与 Request Payload的区别

    在vue项目中使用axios发post请求时候,后台返回500. 发现是form Data 和 Request payload的问题. 后台对两者的处理方式不同,导致我们接收不到数据. 解决方案:使用 ...

  8. VS2017编写c/c++汇编函数并调用

    首先在VS里面创建个空项目,然后添加汇编文件 .asm,    右键asm文件属性  --- 常规,改成下图的设置  , 从生成中排除改为否, 项类型改为自定义生成工具 然后点确定. 再次右键asm文 ...

  9. ModelSerializer,序列化与反序列化整合

    复习 """ 1.解析模块:全局局部配置 REST_FRAMEWORK = { # 全局解析类配置 'DEFAULT_PARSER_CLASSES': [ 'rest_f ...

  10. XSS常见攻击与防御

    XSS攻击全称跨站脚本攻击,是为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XSS,XSS是一种在web应用中的计算机安全漏洞,它允许恶意 ...