小程序模板網(wǎng)

微信小程序?qū)崿F(xiàn)各種特效實(shí)例

發(fā)布時(shí)間:2018-04-26 12:01 所屬欄目:小程序開發(fā)教程

寫在前面

 

最近在負(fù)責(zé)一個(gè)微信小程序的前端以及前后端接口的對(duì)接的項(xiàng)目,整體上所有頁(yè)面的布局我都已經(jīng)搭建完成,里面有一些常用的特效,總結(jié)一下,希望對(duì)大家和我都能有所幫助

實(shí)例1:滾動(dòng)tab選項(xiàng)卡

 

先看一下效果圖吧,能夠點(diǎn)擊菜單或滑動(dòng)頁(yè)面切換,tab菜單部分可以實(shí)現(xiàn)左右滾動(dòng)

好了,看一下我的源碼吧!<喜歡的話拿走不謝喲>

1、wxml

  1. <!-- tab header -->
  2. <scroll-view scroll-x="true" class="tab-h" scroll-left="{{scrollLeft}}">
  3. <view class="tab-item {{currentTab==0?'active':''}}" data-current="0" bindtap="swichNav">全部</view>
  4. <view class="tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="swichNav">營(yíng)銷系統(tǒng)</view>
  5. <view class="tab-item {{currentTab==2?'active':''}}" data-current="2" bindtap="swichNav">家居建材</view>
  6. <view class="tab-item {{currentTab==3?'active':''}}" data-current="3" bindtap="swichNav">美妝護(hù)膚</view>
  7. <view class="tab-item {{currentTab==4?'active':''}}" data-current="4" bindtap="swichNav">數(shù)碼電器</view>
  8. <view class="tab-item {{currentTab==5?'active':''}}" data-current="5" bindtap="swichNav">母嬰玩具</view>
  9. <view class="tab-item {{currentTab==6?'active':''}}" data-current="6" bindtap="swichNav">零元購(gòu)活動(dòng)</view>
  10. </scroll-view>
  11. <!-- tab content -->
  12. <swiper class="tab-content" current="{{currentTab}}" duration="300" bindchange="switchTab" style="max-height:{{winHeight}}rpx">
  13. <swiper-item wx:for="{{[0,1,2,3,4,5,6]}}">
  14. <scroll-view scroll-y="true" class="scoll-h">
  15. <block wx:for="{{[1,2,3,4,5,6,7]}}" wx:key="*this">
  16. <view class='goods-Wrapper'>
  17. <image mode='widthFix' class="goods-img" src='../../image/goods1.jpg'></image>
  18. <view class="goods-info">
  19. <view>周邊團(tuán)門店微營(yíng)銷系統(tǒng)年費(fèi)</view>
  20. <view>
  21. <text class='price'>¥298.00</text>
  22. <text class='line-delete'>
  23. ¥298.00
  24. </text>
  25. <label>
  26. <button><image mode='widthFix' src='../../image/icon1.png'></image>1人團(tuán)</button>
  27. <button><image mode='widthFix' src='../../image/icon2.png'></image>去開團(tuán)</button>
  28. </label>
  29. </view>
  30. </view>
  31. </view>
  32. </block>
  33. </scroll-view>
  34. </swiper-item>
  35. </swiper>
 
2、wxss <我只展示了tab菜單處的wxss,頁(yè)面的樣式就不在列出>
  1. .tab-h {
  2. height: 80rpx;
  3. width: 100%;
  4. box-sizing: border-box;
  5. overflow: hidden;
  6. line-height: 80rpx;
  7. background: #f7f7f7;
  8. font-size: 14px;
  9. white-space: nowrap;
  10. position: fixed;
  11. top: 0;
  12. left: 0;
  13. z-index: 99;
  14. }
  15.  
  16. .tab-item {
  17. margin: 0 36rpx;
  18. display: inline-block;
  19. }
  20.  
  21. .tab-item.active {
  22. color: #4675f9;
  23. position: relative;
  24. }
  25.  
  26. .tab-h .tab-item.active:after {
  27. content: "";
  28. display: block;
  29. height: 8rpx;
  30. width: 115rpx;
  31. background: #4675f9;
  32. position: absolute;
  33. bottom: 0;
  34. left: 5rpx;
  35. border-radius: 16rpx;
  36. }
  37.  
  38. .tab-h .tab-item:nth-child(1).active:after {
  39. width: 52rpx;
  40. }
3、js
  1. var app = getApp();
  2. Page({
  3. data: {
  4. winHeight: "",//窗口高度
  5. currentTab: 0, //預(yù)設(shè)當(dāng)前項(xiàng)的值
  6. scrollLeft: 0, //tab標(biāo)題的滾動(dòng)條位置
  7. expertList: [{ //假數(shù)據(jù)
  8. img: "",
  9. name: "",
  10. tag: "",
  11. answer: 134,
  12. listen: 2234
  13. }]
  14. },
  15. // 滾動(dòng)切換標(biāo)簽樣式
  16. switchTab: function (e) {
  17. this.setData({
  18. currentTab: e.detail.current
  19. });
  20. this.checkCor();
  21. },
  22. // 點(diǎn)擊標(biāo)題切換當(dāng)前頁(yè)時(shí)改變樣式
  23. swichNav: function (e) {
  24. var cur = e.target.dataset.current;
  25. if (this.data.currentTaB == cur) { return false;


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉(cāng)庫(kù):starfork
本文地址:http://22321a.com/wxmini/doc/course/24105.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢:800182392 點(diǎn)擊咨詢
QQ在線咨詢