小程序仿QQ右滑效果

之前项目有了需求就是列表右滑出现功能栏,类似QQ有右滑删除效果


话不多说,上代码

<view class="container">

    <view class="body-list">

        <view class="list-continer" wx:for="{{list}}" wx:key="index">

            <view class="list-item {{index===listIndex?'on':''}}" >

                <view class="item-info" bindtouchstart="touchS" bindtouchmove="touchM" data-index="{{index}}">

                    <view class="item-info-next">

                        <view class="item-content">

                            <image src="{{item.memberLogo}}" mode="aspectFill"></image>

                            <view class="content">

                                <text class="content-title">{{item.writerName || item.stagename || ''}}</text>

                                <label><i class="iconfont iconYISHUJIA"></i> Y{{item.writerFlag || 3}} {{item.levelName}}</label>

                                <text class="content-tip" decode="{{true}}">粉丝:{{item.fansCount || 0}}&nbsp;&nbsp;&nbsp;&nbsp;作品:{{item.goodsCount || 0}}</text>

                            </view>

                        </view>

                        <view class="edit-btn" bindtap="jump" data-url="/pages/mine/pages/user-setting/artist-data/artist-data?id={{item.id}}">编辑</view>

                    </view>

                </view>

                <view class="list-right">

                    <view bindtap="cannelRightTap">取消</view>

                    <view>更换艺术家</view>

                    <view bindtap="delTap" data-id="{{item.writerId}}">删除艺术家</view>

                </view>

            </view>

        </view>

    </view>

    <view class="created-btn" bindtap="jump" data-url="/pages/mine/pages/user-setting/artist-data/artist-data">创建艺术家</view>

</view>


 /**

   * 页面的初始数据

   */

  data: {

    list:[],

    listIndex:null,

    page:1,

    isMore:true

  },

  /**

   * 生命周期函数--监听页面加载

   */

  onLoad: function (options) {

    this.init();

  },

  init(isLoading=false){

    if(!this.data.isMore) return;

    app.wxapi.showLoading('加载中~');

    mineApi.getWriterInfoList({

      start: 0,

      page: this.data.page,

      limit: 10,

    }).then(res=>{

      wx.hideLoading();

      if(res.code==200){

        if(res.data.length<10) this.data.isMore=false;

        ++this.data.page;

        this.setData({list:isLoading?[...this.data.list,...res.data]:res.data})

      }else app.wxapi.showToast(res.msg);

    })

  },

  touchS(e) {

    // 获得起始坐标

    this.startX = e.touches[0].clientX;

    this.startY = e.touches[0].clientY;

  }, 

  touchM(e) {

    // 获得当前坐标

    this.currentX = e.touches[0].clientX;

    this.currentY = e.touches[0].clientY;

    const x = this.startX - this.currentX; //横向移动距离

    const y = Math.abs(this.startY - this.currentY); //纵向移动距离,若向左移动有点倾斜也可以接受

    if (x > 35 && y < 110) {

    //向左滑是显示删除

      this.setData({listIndex: e.currentTarget.dataset.index})

    } else if (x < -35 && y < 110) {

    //向右滑

      this.setData({listIndex: null})

    }

  },

  cannelRightTap(){

    this.setData({listIndex: null})

  },

  delTap(e){

    var _that = this;

    const{id}=e.currentTarget.dataset;

    wx.showModal({

        title: '温馨提示',

        content: `是否确认删除该艺术家?`,

        confirmText: '确定',

        confirmColor: '#FE5250',

        success(modelRes) {

            if (modelRes.confirm) {

              app.wxapi.showLoading("操作中~")

              mineApi.delWriterInfo({"brokerId": _that.data.userInfo.id,"writerId": id}).then(res=>{

                wx.hideLoading()  

                if(res.code==200){

                  app.wxapi.showToast('已删除')

                  _that.init();

                  _that.setData({listIndex:null})

                }else app.wxapi.showToast(res.code)

              })

            } 

        }

    })

  },


.container{

    .body-list{

        width: 100%;

        margin-top: 30rpx;

        padding-bottom: 150rpx;

        .list-continer{

            width: 100%;

            height: 210rpx;

            position: relative;

            .list-item{

                width: 100%;

                height: 100%;

                position: relative;

                .item-info{

                    width: 100%;

                    height: 100%;

                    position: absolute;

                    left: 0;

                    padding: 0 30rpx;

                    transition: 0.3s;

                    background-color: #262626;

                    .item-info-next{

                        width: 100%;

                        height: 100%;

                        display: flex;

                        align-items: center;

                        justify-content: space-between;

                        border-bottom: 1rpx solid #707070;

                        .item-content{

                            flex: 1;

                            display: flex;

                            height: 100%;

                            align-items: center;

                            image{

                                width: 120rpx;

                                height: 120rpx;

                                overflow: hidden;

                                background-color: #707070;

                                border-radius: 50%;

                            }

                            .content{

                                width: 450rpx;

                                height: 100%;

                                display: flex;

                                flex-direction: column;

                                justify-content: space-between;

                                padding: 30rpx 0;

                                padding-left: 30rpx;

                                .content-title{

                                    font-size: 36rpx;

                                    font-weight: 300;

                                    color: #EBEAEA;

                                }

                                label{

                                    font-size: 24rpx;

                                    font-weight: 300;

                                    color: #FF8601;

                                    i{

                                        font-size: 25rpx;

                                        color: #FF8601;

                                        margin-right: 5rpx;

                                    }

                                }

                                .content-tip{                     

                                    font-size: 28rpx;

                                    color: #979393;

                                }

                            }

                        }

                        .edit-btn{

                            width: 120rpx;

                            height: 60rpx;

                            background: #FF8601;

                            border-radius: 50rpx;

                            font-size: 32rpx;

                            font-weight: 300;

                            line-height: 60rpx;

                            text-align: center;

                            color: #EBEAEA;

                        }

                    }

                }

                .list-right{

                    width: 480rpx;

                    position: absolute;

                    right: -480rpx;

                    height: 100%;

                    transition: 0.3s;

                    display: flex;

                    view{

                        width: 160rpx;

                        height: 100%;

                        text-align: center;

                        line-height: 210rpx;

                        background: #979393;

                        font-size: 24rpx;

                        font-weight: 300;

                        color: #EBEAEA;

                        &:nth-of-type(2){

                            width: 160rpx;

                            height: 100%;

                            background: #FF8601;

                        }

                        &:last-of-type{

                            width: 160rpx;

                            height: 100%;

                            background: #A91D33;

                        }

                    }

                }

                &.on{

                    .item-info{

                        left: -480rpx;

                    }

                    .list-right{

                        position: absolute;

                        right: 0;

                    }

                }

            }

            &:last-of-type{

                .list-item{

                    .item-info-next{

                        border:none;

                    }

                }


            }

        }

    }

    .created-btn{

        width: 689rpx;

        height: 90rpx;

        background: #A91D33;

        border-radius: 5rpx;

        position: fixed;

        bottom: 30rpx;

        left: 0;

        right: 0;

        margin: 0 auto;

        font-size: 36rpx;

        font-weight: 300;

        text-align: center;

        line-height: 90rpx;

        color: #EBEAEA;

    }

}


效果简单 多谢支持  如有bug  敬请赐教

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,271评论 5 466
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,725评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,252评论 0 328
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,634评论 1 270
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,549评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 47,985评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,471评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,128评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,257评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,233评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,235评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,940评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,528评论 3 302
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,623评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,858评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,245评论 2 344
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,790评论 2 339

推荐阅读更多精彩内容