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

WeChat applet realizes multi-line text scrolling effect

This article example shares the specific code for...

Implementing a puzzle game with js

This article shares the specific code of js to im...

MySQL full-text search Chinese solution and example code

MySQL full text search Chinese solution Recently,...

JavaScript implements draggable progress bar

This article shares the specific code of JavaScri...

Docker advanced method of rapid expansion

1. Command method Run the nginx service in the cr...

Differences between MySQL CHAR and VARCHAR when storing and reading

Introduction Do you really know the difference be...

Detailed explanation of Nginx static file service configuration and optimization

Root directory and index file The root directive ...

Using js to achieve waterfall effect

This article example shares the specific code of ...

Detailed tutorial on deploying SpringBoot + Vue project to Linux server

Preface Let me share with you how I deployed a Sp...

Set the width of the table to be fixed so that it does not change with the text

After setting the table width in the page to width...

Detailed explanation of mysql permissions and indexes

mysql permissions and indexes The highest user of...

Linux common text processing commands and vim text editor

Today, let's introduce several common text pr...

Use of Linux tr command

1. Introduction tr is used to convert or delete a...