uniapp tab选项卡简单demon
2021/6/12 18:21:37
本文主要是介绍uniapp tab选项卡简单demon,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<template> <view class="content"> <view class="title-bar"> <view :class="selIndex==n?'selIndex':''" v-for="(i,n) in titleList" @click="selIndexs(n)" :key="n">{{ i }} </view> </view> <view class="tab"> <scroll-view class="tab-scroll-view" :scroll-left="scrollLeft" scroll-with-animation :scroll-x="true"> <view class="tab-item" v-for="(item, index) in titleList" :key="index" @touchstart="start" @touchmove="move" @touchend="end"> {{item}} </view> </scroll-view> </view> </view> </template> <script> export default { data() { return { scrollLeft: 0, selIndex: 0, titleList: ['待付款', '待收货', '已收货', '待评价', '售后'], winWidth: 0, startX: 0, moveX: 0 } }, onl oad() { this.getSysInfo() }, methods: { getSysInfo () { let that = this uni.getSystemInfo({ complete(res) { that.winWidth = res.windowWidth console.log(that.winWidth) } }) }, selIndexs (n) { this.selIndex = n this.scrollLeft = n*this.winWidth }, start (e) { this.startX = e.touches[0].clientX }, move (e) { this.moveX = e.touches[0].clientX }, end (e) { e.preventDefault(); if (this.moveX - this.startX < 0) { if (this.titleList.length*this.winWidth>this.scrollLeft) { this.scrollLeft += this.winWidth if ((this.titleList.length-1) > this.selIndex) { this.selIndex +=1 } } } else { if (this.scrollLeft == 0) { this.scrollLeft = 0 this.selIndex = 0 } else { this.scrollLeft -= this.winWidth this.selIndex -= 1 } } console.log(this.scrollLeft) console.log(this.selIndex) } } } </script> <style> .content { display: flex; flex-direction: column; align-items: center; justify-content: center; } .title-bar { width: 100%; height: 40px; font-size: 15px; display: flex; align-items: center; justify-content: space-around; } .selIndex { color: red; } .tab-scroll-view { width: 750rpx; height: 100vh; flex-direction: row; white-space: nowrap; } .tab-item { display: inline-block; width: 100vw; height: 100%; font-size: 16px; color: #555; border: 1px solid yellow; transition: all .5 ease-in-out; } </style>
这篇关于uniapp tab选项卡简单demon的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?
- 2024-05-09企业src漏洞挖掘-有意思的命令执行
- 2024-05-08阿里云域名注册流程,分享给第一次购买域名的新手站长!
- 2024-05-082024年,行业变动下的程序员应该首先学习哪种编程语言?