寫在前面
最近在負責一個微信小程序的前端以及前后端接口的對接的項目,整體上所有頁面的布局我都已經搭建完成,里面有一些常用的特效,總結一下,希望對大家和我都能有所幫助
實例1:滾動tab選項卡
先看一下效果圖吧,能夠點擊菜單或滑動頁面切換,tab菜單部分可以實現左右滾動

好了,看一下我的源碼吧!<喜歡的話拿走不謝喲>
1、wxml
-
<!-- tab header -->
-
<scroll-view scroll-x="true" class="tab-h" scroll-left="{{scrollLeft}}">
-
<view class="tab-item {{currentTab==0?'active':''}}" data-current="0" bindtap="swichNav">全部</view>
-
<view class="tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="swichNav">營銷系統</view>
-
<view class="tab-item {{currentTab==2?'active':''}}" data-current="2" bindtap="swichNav">家居建材</view>
-
<view class="tab-item {{currentTab==3?'active':''}}" data-current="3" bindtap="swichNav">美妝護膚</view>
-
<view class="tab-item {{currentTab==4?'active':''}}" data-current="4" bindtap="swichNav">數碼電器</view>
-
<view class="tab-item {{currentTab==5?'active':''}}" data-current="5" bindtap="swichNav">母嬰玩具</view>
-
<view class="tab-item {{currentTab==6?'active':''}}" data-current="6" bindtap="swichNav">零元購活動</view>
-
</scroll-view>
-
<!-- tab content -->
-
<swiper class="tab-content" current="{{currentTab}}" duration="300" bindchange="switchTab" style="max-height:{{winHeight}}rpx">
-
<swiper-item wx:for="{{[0,1,2,3,4,5,6]}}">
-
<scroll-view scroll-y="true" class="scoll-h">
-
<block wx:for="{{[1,2,3,4,5,6,7]}}" wx:key="*this">
-
<view class='goods-Wrapper'>
-
<image mode='widthFix' class="goods-img" src='../../image/goods1.jpg'></image>
-
<view class="goods-info">
-
<view>周邊團門店微營銷系統年費</view>
-
<view>
-
<text class='price'>¥298.00</text>
-
<text class='line-delete'>
-
¥298.00
-
</text>
-
<label>
-
<button><image mode='widthFix' src='../../image/icon1.png'></image>1人團</button>
-
<button><image mode='widthFix' src='../../image/icon2.png'></image>去開團</button>
-
</label>
-
</view>
-
</view>
-
</view>
-
</block>
-
</scroll-view>
-
</swiper-item>
-
</swiper>
2、wxss <我只展示了tab菜單處的wxss,頁面的樣式就不在列出>
-
.tab-h {
-
height: 80rpx;
-
width: 100%;
-
box-sizing: border-box;
-
overflow: hidden;
-
line-height: 80rpx;
-
background: #f7f7f7;
-
font-size: 14px;
-
white-space: nowrap;
-
position: fixed;
-
top: 0;
-
left: 0;
-
z-index: 99;
-
}
-
-
.tab-item {
-
margin: 0 36rpx;
-
display: inline-block;
-
}
-
-
.tab-item.active {
-
color: #4675f9;
-
position: relative;
-
}
-
-
.tab-h .tab-item.active:after {
-
content: "";
-
display: block;
-
height: 8rpx;
-
width: 115rpx;
-
background: #4675f9;
-
position: absolute;
-
bottom: 0;
-
left: 5rpx;
-
border-radius: 16rpx;
-
}
-
-
.tab-h .tab-item:nth-child(1).active:after {
-
width: 52rpx;
-
}
3、js
-
var app = getApp();
-
Page({
-
data: {
-
winHeight: "",//窗口高度
-
currentTab: 0, //預設當前項的值
-
scrollLeft: 0, //tab標題的滾動條位置
-
expertList: [{ //假數據
-
img: "",
-
name: "",
-
tag: "",
-
answer: 134,
-
listen: 2234
-
}]
-
},
-
// 滾動切換標簽樣式
-
switchTab: function (e) {
-
this.setData({
-
currentTab: e.detail.current
-
});
-
this.checkCor();
-
},
-
// 點擊標題切換當前頁時改變樣式
-
swichNav: function (e) {
-
var cur = e.target.dataset.current;
-
if (this.data.currentTaB == cur) { return false;
|