微信小程序块导航
2024-10-08 09:47:23
1.wxml页面
<!--index.wxml-->
<swiper current="{{currentTab}}" class="swiper-box" duration="300" style="height:362rpx" bindchange="bindChange"> <!-- 我是哈哈 -->
<swiper-item>
<view class="page__bd">
<view class="weui-grids">
<block wx:for-items="{{grids}}" wx:key="{{index}}">
<view class="weui-grid" hover-class="weui-grid_active" data-index="{{index}}" data-id="{{0}}" bindtap="click">
<image class="weui-grid__icon" src="../../images/icon_tabbar.png" />
<view class="weui-grid__label">{{'哈哈-' + index}}</view>
</view>
</block>
</view>
</view>
</swiper-item> <!-- 我是呵呵 -->
<swiper-item>
<view class="page__bd">
<view class="weui-grids">
<block wx:for-items="{{grids}}" wx:key="{{index}}">
<view class="weui-grid" hover-class="weui-grid_active" data-index="{{index}}" data-id="{{1}}" bindtap="click">
<image class="weui-grid__icon" src="../../images/icon_tabbar.png" />
<view class="weui-grid__label">{{'呵呵-' + index}}</view>
</view>
</block>
</view>
</view>
</swiper-item> </swiper> <view class="indicator">
<block wx:for="{{swiperList}}">
<view class="swiper_item" style="background-color:{{index == currentTab?'#04b00f':'#aaaaaa'}};"></view>
</block>
</view>
2.js页面
//获取应用实例
var app = getApp() Page({
data: {
currentTab: 0,
grids: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
swiperList:[0, 1, 2, 3, 4]
},
onLoad: function () {
},
click: function (e) {
console.log(e.currentTarget.dataset.id)
console.log(e.currentTarget.dataset.index)
wx.showToast({
title: '第' + e.currentTarget.dataset.id + '栏' + '第' + e.currentTarget.dataset.index + '个',
icon: 'success',
duration: 1500
})
},
/**
* 滑动切换tab
*/
bindChange: function (e) {
console.log(e.detail.current)
this.setData({ currentTab: e.detail.current });
},
})
3.样式wxss页面
/**index.wxss**/ .swiper-box {
display: block;
height: 100%;
width: 100%;
overflow: hidden;
} .swiper-box view {
text-align: center;
} .weui-grids {
border-top: 1rpx solid #d9d9d9;
border-left: 1rpx solid #d9d9d9;
overflow: hidden;
} .weui-grid {
position: relative;
float: left;
padding: 20px 10px;
width: 20%;
box-sizing: border-box;
/*border-right: 1rpx solid #D9D9D9;
border-bottom: 1rpx solid #D9D9D9;*/
} .weui-grid__icon {
display: block;
width: 28px;
height: 28px;
margin: 0 auto;
} .weui-grid__label {
margin-top: 5px;
display: block;
text-align: center;
color: #000;
font-size: 14px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
} .indicator {
width: 100%;
height: 60rpx;
display:flex;
flex-direction:row;
justify-content:center;
align-items:center;
background: #eee;
} .swiper_item {
margin: 15rpx 10rpx;
position: relative;
float: left;
width: 30rpx;
height: 30rpx;
border-radius: 50%;
background-color: #aaa;
}
最新文章
- [原]CentOS7部署PostGis
- Linux下安装流量监控工具iftop
- asp.net 使用DroDownList来实现二级联动
- iOS开发笔记1:[转]导航栏里的";Back";按钮显示不出来
- Android总结篇系列:Android Service
- graph | hungary
- jQuery源码的几篇文章
- Google Chrome七大新特性
- UNIX环境高级编程-环境配置
- [原创]谷歌插件 - YE启动助手(YeLauncher)
- (转载)c库不正确问题
- 数据库性能高校:CPU使用过高(下)
- 用命令行方式关闭linux防火墙
- 为实体类增加toJSON方法
- activemq修改端口
- Egret里用矢量挖圆形的洞
- Linux下solr集群搭建
- IIC总线初识
- php里input数组的应用
- i春秋CTF web题(1)