Mini Program to Implement Slider Effect

Mini Program to Implement Slider Effect

This article example shares the specific code for the small program to achieve the sliding block effect for your reference. The specific content is as follows

When you copy, just make sure to change the list data of the js logic.

CSS style of the applet

.box {
    width: 100vw;
    background: #F2F2F2;
    transition: all 3s;
}

.box-b {
    height: 8vh;
    width: 100%;
    display: flex;
    justify-content: space-between;
    background-color: #FAFAFA;
    align-items: center;
    padding: 0 30rpx;
    box-sizing: border-box;
}

.box-r1 {
    font-size: 24rpx;
    color: red;
}

.box-r2 {
    font-size: 28rpx;
    padding: 20rpx 50rpx;
    border-radius: 50rpx;
    color: #fff;
    background-color: #FF6C3B;
}

.box-t {
    height: 92vh;
    overflow-y: auto;
    overflow-x:hidden;
    padding: 0 25rpx;
}

.box-top {
    width: 90vw;
    height: 22vw;
    margin-top: 20rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}

.boxs {
    width: 105vw;
    height: 20vw;
    margin-top: 20rpx;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
}

.boxs-1 {
    width: 100vw;
    height: 20vw;
    background: white;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    padding: 10rpx 0;
    border-radius: 10px;
    margin-left: 20px;
}

.boxs-1 > view:first-child {
    width: 10vw;
    line-height: 18vw;
    text-align: center;
    /* background: #ccc; */
    height: 20vw;
}

.boxs-1 > view:nth-child(2) {
    width: 20vw;
    /* background: #ccc; */
    height: 100%;
    border-radius: 20rpx;
}

image {
    width: 100%;
    height: 100%;
    border-radius: 20rpx;
}

.boxs-1 > view:last-child {
    width: 60vw;
    /* background: #ccc; */
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}
.boxs-1 > view:last-child>view{
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    position: relative;
    left: 30rpx;
}
text {
    width: 60vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.boxs-2 {
    width: 120rpx;
    height: 170rpx;
    text-align: center;
    line-height: 170rpx;
    background: #e64340;
    font-size: 24rpx;
    color: #fff;
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
}
.red_cart{
    color: red;
    position: relative;
    right: 40px;
}

wxml style of applet

<view class="box">
    <view class="box-t">
        <movable-area class="box-top" wx:for="{{list}}" wx:key="index">
            <movable-view class="boxes"
                          direction="horizontal"
                          animation="{{true}}"
                          inertia="true"
                          out-of-bounds="false"
            >
                <view class="boxs-1">
                    <view>
                        <checkbox checked="{{selected}}" wx:key="index" bindtap="chec" data-selected="{{item}}"></checkbox>
                    </view>
                    <view>
                        <image src="{{item.pic}}"></image>
                    </view>
                    <view class="cart_list">
                        <text>{{item.name}}</text>
                        <view>
                            <view class="red_cart">¥{{item.price}}</view>
                            <view>
                                <van-stepper class="cart_vant"
                                        value="{{ item.number }}"
                                        bind:change="onChange" data-key="{{item.key}}"/>
                            </view>
                        </view>
                    </view>
                </view>
                <view class="boxs-2" bindtap="del" data-key="{{item.key}}">Delete</view>
            </movable-view>
        </movable-area>
    </view>
    <view class="box-b">
        <view class="box-r1">Total:¥{{price}}</view>
        <view class="box-r2">Go to checkout</view>
    </view>
</view>

Mini Program js

// pages/sales/sales.js
let {
    getShop,
    getRemove,
    modifyNumber,
    getSelected
} = require('../../http/api')
Page({
    onShareAppMessage() {
        return {
            title: 'movable-view',
            path: 'page/component/pages/movable-view/movable-view'
        }
    },

    data: {
        x: 0,
        scale: 2,
        list: [], //You can now define the list data test using price: 0,
        selected: []
    },
    del(e) {
        console.log(e.currentTarget.dataset.key)
        var keys = e.currentTarget.dataset.key
        var token = wx.getStorageSync('token')
        getRemove(token, keys).then(res => {
            // console.log(res)
        })
        this.getShop()
    },
    onChange(e) {
        console.log(e.currentTarget.dataset.key)
        console.log(e.detail)
        var token = wx.getStorageSync('token')
        var key = e.currentTarget.dataset.key
        var number = e.detail
        modifyNumber(token, key, number).then(res => {
            // console.log(res)
        })
        this.getShop()
    },
    tap() {
        this.setData({
            x: 0,
        })
    },
    getShop() {
        getShop().then(res => {
            this.setData({
                list: res.items
            })
        })
    },
    chec(e) {
        this.getShop()
    },
    onLoad: function (options) {
        getShop().then(res => {
            this.setData({
                list: res.items
            })
            this.data.list.forEach(i => {
                var token = wx.getStorageSync('token')
                var key = i.key
                var selected = i.selected
                this.setData({
                    selected: selected
                })
                getSelected(token, key, selected).then(res => {
                    this.setData({
                        price: res.data.price
                    })
                })
            })


        })

    },
    onShow: function () {
        this.getShop()
        if (wx.getStorageSync('token')) {
            wx.hideLoading()
        } else {
            wx.showLoading({
                title: 'Please log in',
            })
        }
    },


    /**
     * Life cycle function--listen for page hiding*/
    onHide: function () {

    },

    /**
     * Life cycle function--monitor page uninstallation*/
    onUnload: function () {

    },


    onReady: function () {

    },
    /**
     * Page related event processing function - listen to user pull-down action */
    onPullDownRefresh: function () {

    },

    /**
     * The function that handles the bottoming event on the page*/
    onReachBottom: function () {

    },

    /**
     * User clicks on the upper right corner to share*/
})

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • WeChat applet two sliding modes (horizontal sliding, vertical sliding) details and example code
  • WeChat applet scroll-view implementation anchor sliding example
  • WeChat applet picture horizontal sliding left and right example
  • WeChat applet swipe left and right to switch pages detailed explanation and example code
  • WeChat applet sidebar sliding effects (slide left and right)
  • Detailed example of WeChat applet page sliding event
  • WeChat applet left and right sliding implementation code
  • Implementation of the swipe left delete function in WeChat applet
  • WeChat applet uses scroll-view tag to realize automatic sliding to the bottom function example code
  • WeChat applet listens to gesture sliding to switch pages

<<:  How to view the storage location of MySQL data files

>>:  Solution to the problem of being unable to access the Internet after Ubuntu restarts in VMWare

Recommend

How to query a record in Mysql in which page of paging

Preface In practice, we may encounter such a prob...

Tutorial on installing mysql5.7.18 on mac os10.12

I searched the entire web and found all kinds of ...

How to query json in the database in mysql5.6 and below

When saving data in MySQL, sometimes some messy a...

Summary of seven MySQL JOIN types

Before we begin, we create two tables to demonstr...

Summary of Mysql exists usage

Introduction EXISTS is used to check whether a su...

Solution to high CPU usage of Tomcat process

Table of contents Case Context switching overhead...

Three ways to create a gray effect on website images

I’ve always preferred grayscale images because I t...

The whole process of configuring hive metadata to MySQL

In the hive installation directory, enter the con...

Steps to enable TLS in Docker for secure configuration

Preface I had previously enabled Docker's 237...

Encoding problems and solutions when mysql associates two tables

When Mysql associates two tables, an error messag...

How to skip errors in mysql master-slave replication

1. Traditional binlog master-slave replication, s...