


Implementation of the combined effect of WeChat mini program tab and swiper
This article mainly introduces the WeChat applet to achieve the combined effect of tab and swiper switching in detail. It has certain reference value. Interested friends can refer to it. I hope it will help everyone.
The example in this article shares with you the specific code for displaying the tab and swiper switching effects of the mini program for your reference. The specific content is as follows
First, the renderings:
The implementation code is as follows:
wxml page
<scroll-view scroll-x="true" class="weui-navbar"> <block wx:for-items="{{tabs}}"> <view id="{{index}}" class="{{activeIndex == index ?'item_on':''}} 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 style:
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 code:
//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: '../logs/logs' }) }, 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 }); } })
Related recommendations :
vue swiper implements component-based development detailed explanation
WeChat Xiaocheng swiper component implements image carousel switching function tutorial
Example of how the WeChat applet implements the non-swiper effect of the normal tab at the top
The above is the detailed content of Implementation of the combined effect of WeChat mini program tab and swiper. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.