search
HomeWeChat AppletMini Program DevelopmentWeChat Mini Program Development Guide: About Carousel

The most common one in the application is probably the carousel. This article talks about the implementation of the carousel. Part of the content comes from the official documents, and adds some problems and experiences of the author in actual operation.
This article is based on the public beta version of the WeChat applet, IDE: WeChat Developer Tool 0.10.102800

Component swiper

WeChat Mini Program Development Guide: About Carousel

When the vertical attribute is not set, or When vertical="false" is set, the indicator point is at the bottom of the component, and the image rotation is from left to right. The effect is as follows:

WeChat Mini Program Development Guide: About Carousel

When vertical="true" is set, the indicator point On the right side of the component, the image carousel goes from bottom to top, and the effect is as follows:

WeChat Mini Program Development Guide: About Carousel

Note: swiper is a container class view, but only components can be placed in it, such as placing other nodes. , will be automatically deleted.

swiper-item

The code is as follows:

<!--main.wxml-->
<view>
    <swiper class="swiper_box" indicator-dots="{{indicatorDots}}" vertical="{{vertical}}"
            autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" bindchange="swiperchange">
        <block wx:for="{{images}}">
            <swiper-item>
                <image src="{{item.picurl}}" class="slide-image"/>
            </swiper-item>
        </block>
    </swiper>
</view>
//main.js
//获取应用实例
var app = getApp()
Page({
    data: {
        indicatorDots: true,
        vertical: true,
        autoplay: true,
        interval: 3000,
        duration: 1000,
        loadingHidden: false  // loading
    },

    //事件处理函数
    swiperchange: function(e) {
        // 此处写 轮播 改变时会触发的 change 事件
    },

    onLoad: function() {
        console.log(&#39;onLoad&#39;)
        var that = this

        //sliderList
        wx.request({
            url: &#39;http://huanqiuxiaozhen.com/wemall/slider/list&#39;,
            method: &#39;GET&#39;,
            data: {},
            header: {
                &#39;Accept&#39;: &#39;application/json&#39;
            },
            success: function(res) {
                that.setData({
                    images: res.data
                })
            }
        })
    }
})

item click event

Bind the event on swiper-item and bind it through the data custom tag fixed data. Then get it through event in function.

<!--main.wxml-->
<view>
    <swiper class="swiper_box" indicator-dots="{{indicatorDots}}" vertical="{{vertical}}"
            autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" bindchange="swiperchange">
        <block wx:for="{{images}}">
            <swiper-item bindtap="itemclick" data-id="{{item.id}}" data-name="{{item.name}}">
                <image src="{{item.picurl}}" class="slide-image"/>
            </swiper-item>
        </block>
    </swiper>
</view>
// 轮播item点击事件
itemclick: function(e) {
    wx.showToast({
        title: e.currentTarget.dataset.id + "",
        icon: &#39;success&#39;,
        duration: 2000
    })
},

Note that the corresponding data can be obtained through event in the bound function. For example: e.currentTarget.dataset.id corresponds to data-id

in wxml. Of course, there is another way. There is no need to bind events, by wrapping an a tag around each swiper-item to jump to the page as a hyperlink.

More WeChat Mini Program Development Guide: For articles related to carousels, please pay attention to the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

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.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)