微信小程序頂部導(dǎo)航欄可滑動(dòng)并選中放大
這篇文章主要介紹了微信小程序頂部導(dǎo)航欄可滑動(dòng)并選中放大,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
老規(guī)矩,先看效果圖

可以看到我們實(shí)現(xiàn)了如下功能
- 1,頂部導(dǎo)航欄
- 2,可以左右滑動(dòng)的導(dǎo)航欄
- 3,選中條目放大
原理其實(shí)很簡(jiǎn)單,我這里把我研究后的源碼發(fā)給大家吧。
wxml文件如下
<!-- 導(dǎo)航欄 -->
<scroll-view scroll-x class="navbar" scroll-with-animation scroll-left="{{scrollLeft}}rpx">
<view class="nav-item" wx:for="{{tabs}}" wx:key="id" bindtap="tabSelect" data-id="{{index}}">
<view class="nav-text {{index==tabCur?'tab-on':''}}">{{item.name}}</view>
</view>
</scroll-view>
wxss文件如下
/* 導(dǎo)航欄布局相關(guān) */
.navbar {
width: 100%;
height: 90rpx;
/* 文本不換行 */
white-space: nowrap;
display: flex;
box-sizing: border-box;
border-bottom: 1rpx solid #eee;
background: #fff;
align-items: center;
/* 固定在頂部 */
position: fixed;
left: 0rpx;
top: 0rpx;
}
.nav-item {
padding-left: 25rpx;
padding-right: 25rpx;
height: 100%;
display: inline-block;
/* 普通文字大小 */
font-size: 28rpx;
}
.nav-text {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
letter-spacing: 4rpx;
box-sizing: border-box;
}
.tab-on {
color: #fbbd08;
/* 選中放大 */
font-size: 38rpx !important;
font-weight: 600;
border-bottom: 4rpx solid #fbbd08 !important;
}
js文件如下
// pages/test2/test2.js
Page({
data: {
tabCur: 0, //默認(rèn)選中
tabs: [{
name: '等待支付',
id: 0
},
{
name: '待發(fā)貨',
id: 1
},
{
name: '待收貨',
id: 2
},
{
name: '待簽字',
id: 3
},
{
name: '待評(píng)價(jià)',
id: 4
},
{
name: '五星好評(píng)',
id: 5
},
{
name: '差評(píng)訂單',
id: 6
},
{
name: '編程小石頭',
id: 8
},
{
name: '小石頭',
id: 9
}
]
},
//選擇條目
tabSelect(e) {
this.setData({
tabCur: e.currentTarget.dataset.id,
scrollLeft: (e.currentTarget.dataset.id - 2) * 200
})
}
})
代碼里注釋很明白了,大家自己跟著多敲幾遍就可以了。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript DSL 流暢接口(使用鏈?zhǔn)秸{(diào)用)實(shí)例
這篇文章主要介紹了JavaScript DSL 流暢接口(使用鏈?zhǔn)秸{(diào)用)實(shí)例,本文講解了DSL 流暢接口、DSL 表達(dá)式生成器等內(nèi)容,需要的朋友可以參考下2015-03-03
JavaScript必知必會(huì)(十) call apply bind的用法說(shuō)明
這篇文章主要介紹了JavaScript必知必會(huì)(十) call apply bind的用法說(shuō)明 的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06
點(diǎn)擊button獲取text內(nèi)容并改變樣式的js實(shí)現(xiàn)
這篇文章主要介紹了點(diǎn)擊button獲取text內(nèi)容并改變樣式的js實(shí)現(xiàn),經(jīng)測(cè)試非常實(shí)用,需要的朋友可以參考下2014-09-09
純JavaScript基于notie.js插件實(shí)現(xiàn)消息提示特效
這篇文章主要介紹了純JavaScript基于notie.js插件實(shí)現(xiàn)消息提示特效,可以制作Alert提示框,確認(rèn)框和帶輸入的消息框,感興趣的小伙伴們可以參考一下2016-01-01
JavaScript switch case 的用法實(shí)例[范圍]
JavaScript switch case 的用法實(shí)例,大家可以參考下。2009-09-09
javascript輕量級(jí)模板引擎juicer使用指南
Juicer 是一個(gè)高效、輕量的前端 (Javascript) 模板引擎,使用 Juicer 可以是你的代碼實(shí)現(xiàn)數(shù)據(jù)和視圖模型的分離(MVC)。2014-06-06

