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

<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. 通过Spring Resource接口获取资源

    目录 1       Resource简介 2       通过ResourceLoader获取资源 3       在bean中获取Resource的方式 1       Resource简介 在S ...

  2. awk从放弃到入门(3):awk变量

    一.变量概述 对于awk来说"变量"又分为"内置变量" 和 "自定义变量" , "输入分隔符FS"和"输出分隔 ...

  3. 基于SILVACO ATLAS的a-IGZO薄膜晶体管二维器件仿真(01)

    最近因为肺炎的缘故,宅在家里不能出门,就翻了下一些资料,刚好研究方向是这个,就简单研究了下.参考资料主要如下: 1.<半导体工艺和器件仿真软件Silvaco TCAD实用教程> 唐龙谷 2 ...

  4. noobSTL-1-配置器-1

    noobSTL-1-配置器-1 1.要点分析 1.1 可能让你困惑的C++语法 组态 即配置. 临时对象 一种无名对象.有时候会刻意地制造临时对象. 静态常量整数成员在class内部直接初始化 con ...

  5. css之变形(transform)

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

  6. (BFS)1097: Yuchang and Zixiang ‘s maze

    1097: Yuchang and Zixiang ‘s maze Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 863 Solved: 149   De ...

  7. 链剖-进阶ing-填坑-NOIP2013-货车运输

    This article is made by Jason-Cow.Welcome to reprint.But please post the writer's address. http://ww ...

  8. Bugku-CTF之文件包含2 (150)

    Day37   文件包含2

  9. K8S集群搭建之软路由的安装

    一.系统要求 ①镜像:win10 ②1C.4G.20G即可 ③仅主机模式(共享网卡上网) ④老毛桃PE ⑤ip为192.168.66网段(因为我设置的其他K8S节点也为该网段)---koolshare ...

  10. AngularJS请求数据提示resource from url not allowed by $sceDelegate policy

    AngularJS iframe跨域打开内容时报错 解决方案 使用  $sceDelegateProvider  配置跨域请求域名 config.js app.config(function($sce ...