最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

uniapp組件之tab選項卡滑動切換功能實現(xiàn)

 更新時間:2023年01月31日 16:11:45   作者:薇森  
這篇文章主要介紹了uniapp組件之tab選項卡滑動切換功能實現(xiàn),本文結合實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧

uniapp組件之tab選項卡滑動切換

  效果如下:

  代碼如下: 

<template>
	<view class="content">
		<view class="nav">
			<!-- 選項卡水平方向滑動,scroll-with-animation是滑動到下一個選項時,有一個延時效果 -->
			<scroll-view class="tab-scroll" scroll-x="true" scroll-with-animation :scroll-left="scrollLeft">
				<view class="tab-scroll_box">
					<!-- 選項卡類別列表 -->
					<view class="tab-scroll_item" v-for=" (item,index) in category" :key="index"  :class="{'active':isActive==index}" @click="chenked(index)">
							{{item.name}}
					</view>
				</view>
			</scroll-view>
		</view>
		<!-- 選項卡內容輪播滑動顯示,current為當前第幾個swiper子項 -->
		<swiper @change="change" :current="isActive" class="swiper-content" :style="fullHeight">
			<swiper-item class="swiperitem-content">
				<scroll-view scroll-y style="height: 100%;">
					<view class="nav_item" >
						選項卡1頁面
					</view>
				</scroll-view>	
			</swiper-item>
			<swiper-item class="swiperitem-content">
				<scroll-view scroll-y style="height: 100%;">
					<view class="nav_item" >
						選項卡2頁面
					</view>
				</scroll-view>	
			</swiper-item>
			<swiper-item class="swiperitem-content">
				<scroll-view scroll-y style="height: 100%;">
					<view class="nav_item" >
						選項卡3頁面
					</view>
				</scroll-view>
			</swiper-item>
			<swiper-item class="swiperitem-content">
				<scroll-view scroll-y style="height: 100%;">
					<view class="nav_item" >
						選項卡4頁面
					</view>
				</scroll-view>	
			</swiper-item>
			<swiper-item class="swiperitem-content">
				<scroll-view scroll-y style="height: 100%;">
					<view class="nav_item" >
						選項卡5頁面
				    </view>
				</scroll-view>	
			</swiper-item>
			<swiper-item class="swiperitem-content">
				<scroll-view scroll-y style="height: 100%;">
					<view class="nav_item" >
						選項卡6頁面
				    </view>
				</scroll-view>	
			</swiper-item>
		</swiper>
	</view>
</template>
<script>
	export default {
		watch:{
			// swiper與上面選項卡聯(lián)動
			currentindex(newval){
				this.isActive = newval;
				this.scrollLeft = 0;
				// 滑動swiper后,每個選項距離其父元素最左側的距離
				for (let i = 0; i < newval - 1; i++) {
					this.scrollLeft += this.category[i].width
				};
			},
		},
		data() {	
			return {
				isActive: 0,
				index: 0,
				currentindex:0,
				category:[
					{
						id:1,
						name:'選項卡一',
					},
					{
						id:2,
						name:'選項卡二',
					},
					{
						id:3,
						name:'選項卡三',
					},
					{
						id:4,
						name:'選項卡四',
					},
					{
						id:5,
						name:'選項卡五',
					},
					{
						id:6,
						name:'選項卡六',
					},
				],
				contentScrollW: 0, // 導航區(qū)寬度
				scrollLeft: 0, // 橫向滾動條位置
				fullHeight:"",	
			}
		},
		mounted() {
			var that = this;
			 //獲取手機屏幕的高度,讓其等于swiper的高度,從而使屏幕充滿
			uni.getSystemInfo({
			      success: function (res) {
				         that.fullHeight ="height:" + res.windowHeight + "px";
				  }
				});
			// 獲取標題區(qū)域寬度,和每個子元素節(jié)點的寬度
			this.getScrollW()
		},
		methods: {
			// 獲取標題區(qū)域寬度,和每個子元素節(jié)點的寬度以及元素距離左邊欄的距離
			getScrollW() {
				const query = uni.createSelectorQuery().in(this);
				query.select('.tab-scroll').boundingClientRect(data => {
					  // 拿到 scroll-view 組件寬度
					  this.contentScrollW = data.width
				 }).exec();
				 query.selectAll('.tab-scroll_item').boundingClientRect(data => {
					 let dataLen = data.length;
					  for (let i = 0; i < dataLen; i++) {
						  //  scroll-view 子元素組件距離左邊欄的距離
						  this.category[i].left = data[i].left;
						 //  scroll-view 子元素組件寬度
						 this.category[i].width = data[i].width
					}
				 }).exec()
			},
			// 當前點擊子元素靠左留一個選項展示,子元素寬度不相同也可實現(xiàn)
			chenked(index) {
				this.isActive = index;
				this.scrollLeft = 0;
				for (let i = 0; i < index - 1; i++) {
					this.scrollLeft += this.category[i].width
				};
			},
			// swiper滑動時,獲取其索引,也就是第幾個
			change(e){
				const {current} = e.detail;
				this.currentindex = current;
			},	
		}
	}
</script>
<style lang="scss">
	page{
		height: 100%;
		display: flex;
		background-color: #FFFFFF;
	}
	.content{
		display: flex;
		flex-direction: column;
		width: 100%;
		flex: 1;
		.nav{
			border-top: 1rpx solid #f2f2f2;
			background-color: #fceeee;	
			position: fixed;
			z-index: 99;
			width: 100%;
			align-items: center;
			height: 100rpx;
			.tab-scroll{
				flex: 1;
				overflow: hidden;
				box-sizing: border-box;
				padding-left: 30rpx;
				padding-right: 30rpx;
				.tab-scroll_box{
					display: flex;
					align-items: center;
					flex-wrap: nowrap;
					box-sizing: border-box;
					.tab-scroll_item{
						line-height: 60rpx;
						margin-right: 35rpx;
						flex-shrink: 0;
						padding-bottom:10px;
						display: flex;
						justify-content: center;
						font-size: 16px;
						padding-top: 10px;
					}
				}
			}
		}
		.swiper-content{
			   padding-top: 120rpx;
			   flex: 1;
			.swiperitem-content{
			    background-color: #ffffff;
				.nav_item{	
					background-color: #FFFFFF;
					padding:20rpx 40rpx 0rpx 40rpx ;
				}
			}
		}	
	}
	.active {
		position: relative;
		color: #ff0000;
		font-weight: 600;
	}
	.active::after {
		content: "";
		position: absolute;
		width: 130rpx;
		height: 4rpx;
		background-color: #ff0000;
		left: 0px;
		right: 0px;
		bottom: 0px;
		margin: auto;
	}
	/* 隱藏滾動條,但依舊具備可以滾動的功能 */
	/deep/.uni-scroll-view::-webkit-scrollbar {
		display: none
	}
</style>

注意:css當中需要加上以下,為了隱藏滾動條,否則會出現(xiàn)下圖效果

/* 隱藏滾動條,但依舊具備可以滾動的功能 */
 
/deep/.uni-scroll-view::-webkit-scrollbar {
 
display: none
 
}

補充:uniapp實現(xiàn)tabs切換(可滑動)

uniapp實現(xiàn)tabs切換(可滑動)

在這里插入圖片描述

<template>
	<view class="body-view">
		<!-- 使用scroll-view實現(xiàn)tabs滑動切換 -->
		<scroll-view class="top-menu-view" scroll-x="true" :scroll-into-view="tabCurrent">
			<view class="menu-topic-view" v-for="item in tabs" :id="'tabNum'+item.id" :key="(item.id - 1)" @click="swichMenu(item.id - 1)">
				<view :class="currentTab==(item.id - 1) ? 'menu-topic-act' : 'menu-topic'">
					<text class="menu-topic-text">{{item.name}}</text>
					<view class="menu-topic-bottom">
						<view class="menu-topic-bottom-color"></view>
					</view>
				</view>
			</view>
		</scroll-view>
		<!-- 內容 -->
		<swiper class="swiper-box-list" :current="currentTab" @change="swiperChange">
			<swiper-item class="swiper-topic-list" v-for="item in swiperDateList" :key="item.id">
				<view class="swiper-item">
					{{item.content}}
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabs: [{
						id: 1,
						name: '推薦'
					},
					{
						id: 2,
						name: '交通交通'
					},
					{
						id: 3,
						name: '住房'
					},
					{
						id: 4,
						name: '社會保障'
					},
					{
						id: 5,
						name: '民生熱點'
					},
					{
						id: 6,
						name: '即日頭條'
					},
					{
						id: 7,
						name: '新聞聯(lián)播'
					},
				],
				currentTab: 0,
				tabCurrent: 'tabNum1',
				// Tab切換內容
				swiperDateList: [{
						id: 1,
						content: '推薦'
					},
					{
						id: 2,
						content: '交通交通'
					},
					{
						id: 3,
						content: '住房'
					},
					{
						id: 4,
						content: '社會保障'
					},
					{
						id: 5,
						content: '民生熱點'
					},
					{
						id: 6,
						content: '即日頭條'
					},
					{
						id: 7,
						content: '新聞聯(lián)播'
					},
				],
			}
		},
		onLoad() {

		},
		methods: {
			swichMenu(id) {
				this.currentTab = id
				console.log(11,id)
				this.tabCurrent = 'tabNum'+ id
			},
			swiperChange(e) {
				console.log(22,e.detail.current)
				let index = e.detail.current
				this.swichMenu(index)
			}
		}
	}
</script>

<style scoped lang="scss">
	.body-view {
		height: 100vh;
		width: 100%;
		display: flex;
		flex: 1;
		flex-direction: column;
		overflow: hidden;
		align-items: flex-start;
		justify-content: center;
	}

	.top-menu-view {
		display: flex;
		position: fixed;
		top: 100rpx;
		left: 0;
		white-space: nowrap;
		width: 100%;
		background-color: #FFFFFF;
		height: 86rpx;
		line-height: 86rpx;
		border-top: 1rpx solid #d8dbe6;

		.menu-topic-view {
			display: inline-block;
			white-space: nowrap;
			height: 86rpx;
			position: relative;

			.menu-topic-text {
				font-size: 30rpx;
				color: #303133;
				padding: 10rpx 40rpx;
			}

			// .menu-topic-act {
			// 	margin-left: 30upx;
			// 	margin-right: 10upx;
			// 	position: relative;
			// 	height: 100%;
			// 	display: flex;
			// 	align-items: center;
			// 	justify-content: center;
			// }

			.menu-topic-bottom {
				position: absolute;
				bottom: 0;
				width: 100%;

				.menu-topic-bottom-color {
					width: 40rpx;
					height: 4rpx;
				}
			}

			.menu-topic-act .menu-topic-bottom {
				display: flex;
				justify-content: center;
			}

			.menu-topic-act .menu-topic-bottom-color {
				background: #3d7eff;
			}



		}


	}

	.swiper-box-list {
		width: 100%;
		padding-top: 200rpx;
		flex:1;
		background-color: #FFFFFF;
		.swiper-topic-list {
		     width: 100%;
		 }
	}
</style>

繼續(xù)加油呀~

到此這篇關于uniapp組件之tab選項卡滑動切換的文章就介紹到這了,更多相關uniapp tab選項卡滑動切換內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Javascript圖像處理—圖像形態(tài)學(膨脹與腐蝕)

    Javascript圖像處理—圖像形態(tài)學(膨脹與腐蝕)

    上一篇文章,我們講解了圖像處理中的閾值函數(shù),這一篇文章我們來做膨脹和腐蝕函數(shù)
    2013-01-01
  • JS如何實現(xiàn)在頁面上快速定位(錨點跳轉問題)

    JS如何實現(xiàn)在頁面上快速定位(錨點跳轉問題)

    本篇文章主要介紹了JS如何實現(xiàn)在頁面上快速定位(錨點跳轉問題),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • js控住DOM實現(xiàn)發(fā)布微博效果

    js控住DOM實現(xiàn)發(fā)布微博效果

    這篇文章主要為大家詳細介紹了js控住DOM實現(xiàn)發(fā)布微博效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-08-08
  • 修改發(fā)貼的編輯功能

    修改發(fā)貼的編輯功能

    修改發(fā)貼的編輯功能...
    2007-03-03
  • 如何實現(xiàn)小程序tab欄下劃線動畫效果

    如何實現(xiàn)小程序tab欄下劃線動畫效果

    這篇文章主要介紹了如何實現(xiàn)小程序tab欄下劃線動畫效果,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-05-05
  • 原生js的ajax和解決跨域的jsonp(實例講解)

    原生js的ajax和解決跨域的jsonp(實例講解)

    下面小編就為大家?guī)硪黄鷍s的ajax和解決跨域的jsonp(實例講解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • 使用TypeScript在接口中定義靜態(tài)方法詳解

    使用TypeScript在接口中定義靜態(tài)方法詳解

    當我們談論面向對象編程時,最難理解的事情之一就是靜態(tài)屬性與實例屬性的概念,尤其是當我們試圖在靜態(tài)類型的基礎上進行動態(tài)語言類型化時,在本文中,我將主要介紹一下如何使用TypeScript在接口中定義靜態(tài)方法,需要的朋友可以參考下
    2023-10-10
  • 小程序Request的另類用法詳解

    小程序Request的另類用法詳解

    這篇文章主要介紹了小程序Request的另類用法詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-08-08
  • JWT?Json?Web?Token全面詳解

    JWT?Json?Web?Token全面詳解

    這篇文章主要為大家介紹了JWT?Json?Web?Token全面詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪<BR>
    2022-11-11
  • 詳解JavaScript實現(xiàn)JS彈窗的三種方式

    詳解JavaScript實現(xiàn)JS彈窗的三種方式

    這篇文章主要為大家介紹了JavaScript實現(xiàn)JS彈窗的三種方式,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助<BR>
    2022-01-01

最新評論

达拉特旗| 沾益县| 城步| 钦州市| 六枝特区| 民乐县| 靖州| 顺平县| 瓮安县| 达尔| 新闻| 广饶县| 盈江县| 长乐市| 青河县| 蒙城县| 天柱县| 宿松县| 光山县| 商河县| 潜山县| 开原市| 山东省| 金乡县| 望谟县| 郁南县| 福海县| 镇宁| 新沂市| 南投市| 浠水县| 衡阳市| 商河县| 黄骅市| 澎湖县| 健康| 柳林县| 洮南市| 宁武县| 吉木萨尔县| 五莲县|