検索
ホームページWeChat アプレットミニプログラム開発WeChatミニプログラムタブとスワイパーの複合効果の実装

WeChatミニプログラムタブとスワイパーの複合効果の実装

Jan 16, 2018 am 09:58 AM
swiper成し遂げるアプレット

本文主要为大家详细介绍了微信小程序实现tab和swiper切换结合效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望帮助到大家。

本文实例为大家分享了小程序实现tab和swiper切换效果展示的具体代码,供大家参考,具体内容如下

先上效果图:

实现代码如下:

wxml页面


<scroll-view scroll-x="true" class="weui-navbar">
  <block wx:for-items="{{tabs}}">
  <view id="{{index}}" class="{{activeIndex == index ?&#39;item_on&#39;:&#39;&#39;}} default-item" bindtap="tabClick" style="width:{{tabW}}px">
  {{item}}
  </view>
 </block>
 <view class="weui-navbar-slider" style="transform:translateX({{slideOffset}}px);"></view>
</scroll-view>
<view class="rec" />
<swiper current="{{activeIndex}}" class="swiper-box" duration="100" bindchange="bindChange">
 <swiper-item class="swiper-item">
  <view class="slide-view">tab0</view>
 </swiper-item>
  <swiper-item class="swiper-item">
  <view class="slide-view">tab1</view>
 </swiper-item>
  <swiper-item class="swiper-item">
  <view class="slide-view">tab2</view>
 </swiper-item>
  <swiper-item class="swiper-item">
  <view class="slide-view">tab3</view>
 </swiper-item>
 <swiper-item class="swiper-item">
  <view class="slide-view">tab4</view>
 </swiper-item>
  <swiper-item class="swiper-item">
  <view class="slide-view">tab5</view>
 </swiper-item>
  <swiper-item class="swiper-item">
  <view class="slide-view">tab6</view>
 </swiper-item>
</swiper>


wxss样式:


page {
 height: 100%;
}
view , scroll-view{
 padding: 0px;
 margin: 0px;
}
.weui-navbar{
 width: 100%;
 position: fixed;
 border-bottom: 1px solid #00bba1;
 box-sizing: border-box;
 white-space: nowrap; 
 z-index: 100;
 background: white;
}
.rec{
 width: 100%;
 height: 7%;
}
.weui-navbar .default-item{
 /*width:25%;*/
 display: inline-block;
 text-align: center;
 font-size: 32rpx;
 box-sizing: border-box;
 height: 7%;
 padding-bottom: 20rpx;
}
.weui-navbar .item_on{
 color: #00bba1;
}
.weui-navbar-slider{
 position: absolute;
 width: 160rpx;
 height: 2px;
 content:"";
 background: #00bba1;
 bottom: 0px;
 left: 12.5rpx;
 transition: transform .3s;
}
.swiper-box{
 height: 900px;
 border-bottom: 1px solid #d1d1d1;
}
.swiper-box .swiper-item{
 text-align: center;
 padding-top: 200rpx;
 height: 100%;
}


js代码:


//index.js
//获取应用实例
var app = getApp();
var mtabW;
Page({
 data: {
 tabs:["综合与绘画","艺术喷漆","泥塑","纸面绘画","布面绘画","中国油画","水墨画"],
 activeIndex:0,
 slideOffset:0,
 tabW:0
 },
 //事件处理函数
 onLoad: function () {
  var that = this;
  wx.getSystemInfo({
   success: function (res) {
    mtabW = res.windowWidth / 4; //设置tab的宽度
    that.setData({
     tabW:mtabW
    })
   }
  });

 },
 bindViewTap: function() {
 wx.navigateTo({
  url: &#39;../logs/logs&#39;
 })
 },
 tabClick:function(e){
  var that = this;
  var idIndex = e.currentTarget.id;
  var offsetW = e.currentTarget.offsetLeft; //2种方法获取距离文档左边有多少距离
  this.setData({
  activeIndex:idIndex,
  slideOffset:offsetW
  });
 },
 bindChange:function(e){
  var current = e.detail.current;
  if((current+1)%4 == 0){

  }
  var offsetW = current * mtabW; //2种方法获取距离文档左边有多少距离
  this.setData({
   activeIndex:current,
   slideOffset:offsetW
  });

 }

})

相关推荐:

vue swiper实现组件化开发详解

微信小程swiper组件实现图片轮播切换功能教程

微信小程序如何实现顶部普通选项卡非swiper效果的实例

以上がWeChatミニプログラムタブとスワイパーの複合効果の実装の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

PhpStorm Mac バージョン

PhpStorm Mac バージョン

最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい