uni-app仿美团美食团购轮播

简介: uni-app仿美团美食团购轮播

uni-app仿美团美食团购轮播

代码

<template>
  <view>
    <view style="display: flex;align-items: center;margin: 20rpx;">
      <text style="font-weight: bold;white-space: nowrap;margin-right: 20rpx;">饮品/甜品</text>
      <view style="width: 100%;">
        <view style="width: 100%;display: flex;background-color: #fff;border-radius: 30rpx;display: flex;align-items: center;padding: 10rpx;">
          <u-icon name="search" style="margin-right: 10rpx;"></u-icon>
          <input style="width: 100%;" placeholder="请输入商家名或商品名称" />
        </view>
      </view>
    </view>
    <view style="background-color: #fff;border-radius: 25rpx;padding: 20rpx;margin: 25rpx;">
      <view style="display: flex;justify-content: space-between;padding: 0 0;">
        <text style="font-weight: bold;margin-bottom: 10rpx;">附近都在喝</text>
        <view style="display: flex;align-items: center;color: orangered;">
          <text>查看更多</text>
          <u-icon name="arrow-right"></u-icon>
        </view>
      </view>
      <view style="background-color: #fff;position: relative;height: 350rpx;
    overflow: hidden;">
        <view style="display: flex;overflow: hidden;position: absolute;"  :style="{'left':marginLeft+'rpx'}">
          <view @touchstart="touchstart" @touchend="touchend($event,index)"  class="item" :style="{'border':index == currentIndex?'':'2rpx solid #eee','margin-right':index == currentIndex?'10rpx':'10rpx','width':index == currentIndex?'440rpx':'170rpx','overflow':index == currentIndex?'':'hidden','transition':isAnimation?'all .3s':''}" v-for="(item,index) in list" style="display: flex;overflow: hidden;border-radius: 15rpx;">
            <view :style="{'transition':isAnimation?'all .3s':''}" style="display: flex;font-size: 25rpx;">
              <view style="margin-right: 10rpx;position: relative;">
                <image style="width: 170rpx;height: 250rpx;border-radius: 10rpx;" :src="item.image"></image>
                <view v-if="index != currentIndex" style="position: absolute;left: 0;bottom: 0;display: flex;flex-direction: column;background-color: #fff;width: 100%;padding: 0 0;">
                  <text style="font-weight: bold;text-align: center;margin-bottom: 5rpx;">青山白柚...</text>
                  <view style="display: flex;align-items: center;color: orangered;margin-bottom: 7rpx;">
                    <text style="font-size: 20rpx;font-weight: bold;">¥</text>
                    <text style="font-size: 25rpx;font-weight: bold;">11.25</text>
                    <view style="border: 2rpx solid orangered;border-radius: 5rpx;padding: 0 5rpx;margin-left: 5rpx;">
                      7.5折
                    </view>
                  </view>
                </view>
              </view>
              <view style="white-space: nowrap;background-color: #f5f5f5;padding: 20rpx;margin-left: -10rpx;margin-top: 20rpx;height: calc(100% - 20rpx);padding-left: 7rpx;">
                <view style="display: flex;flex-direction: column;">
                  <text style="font-weight: bold;font-size: 30rpx;">爆品冷萃茶2选1</text>
                  <text style="color: gray;white-space: nowrap;">茶百道(金山枫泾古...</text>
                </view>
                <view style="background-color: orangered;color: #fff;width: fit-content;padding: 5rpx;border-radius: 10rpx;margin-top: 10rpx;">
                  <text>回头客多</text>
                </view>
                <view style="display: flex;margin-top: 10rpx;align-items: center;">
                  <view style="font-size: 30rpx;color: orangered;">
                    <text style="font-size: 25rpx;">¥</text>
                    <text style="font-size: 30rpx;">6.66</text>
                  </view>
                  <view style="border-radius: 5rpx;color: orangered;border: 2rpx solid orangered;padding: 5rpx;margin: 0 10rpx;">8.4折</view>
                  <view style="text-decoration: line-through;color: gray;">¥8</view>
                </view>
              </view>
            </view>
          <!--  <view style="display: flex;flex-direction: column;width: 200rpx;" v-else>
              <view style="margin-right: 10rpx;">
                <image style="width: 150rpx;height: 200rpx;border-radius: 10rpx;" :src="item.image"></image>
              </view>
              <view>
                <text>青山白柚...</text>
                <view>
                  <view style="font-weight: bold;color: orangered;">
                    <text>¥</text>
                    <text>11.25</text>
                    <view>7.5折</view>
                  </view>
                </view>
              </view>
            </view> -->
          </view>
        </view>
        <!-- <u-swiper :list="list"></u-swiper> -->
      </view>
    </view>
  </view>
</template>
<script>
  export default {
    data() {
      return {
        isAnimation:true,
        currentIndex:1,
        marginLeft:-175,
        originList: [{
            id:0,
            image: 'https://img0.baidu.com/it/u=4147813612,122739285&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=666',
            title: '蒹葭苍苍,白露为霜。所谓伊人,在水一方'
          },{
            id:0,
            image: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.2C5SSJ3NYLOT3Jr6xeUj8gHaLH?w=186&h=279&c=7&r=0&o=5&pid=1.7',
            title: '蒹葭苍苍,白露为霜。所谓伊人,在水一方'
          },
          {
            id:1,
            image: 'https://img2.baidu.com/it/u=2818603572,2916403253&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=666',
            title: '溯洄从之,道阻且长。溯游从之,宛在水中央'
          },
          {
            id:2,
            image: 'https://img.zcool.cn/community/01dd5a5e4ccad5a80120a895c06cc9.jpg@1280w_1l_2o_100sh.jpg',
            title: '溯洄从之,道阻且长。溯游从之,宛在水中央'
          }
        ],
        list: [{
            id:0,
            image: 'https://img0.baidu.com/it/u=4147813612,122739285&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=666',
            title: '蒹葭苍苍,白露为霜。所谓伊人,在水一方'
          },{
            id:0,
            image: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.2C5SSJ3NYLOT3Jr6xeUj8gHaLH?w=186&h=279&c=7&r=0&o=5&pid=1.7',
            title: '蒹葭苍苍,白露为霜。所谓伊人,在水一方'
          },
          {
            id:1,
            image: 'https://img2.baidu.com/it/u=2818603572,2916403253&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=666',
            title: '溯洄从之,道阻且长。溯游从之,宛在水中央'
          },
          {
            id:2,
            image: 'https://img.zcool.cn/community/01dd5a5e4ccad5a80120a895c06cc9.jpg@1280w_1l_2o_100sh.jpg',
            title: '溯洄从之,道阻且长。溯游从之,宛在水中央'
          }
        ],
        startX:0
      }
    },
    methods: {
      touchstart(e) {
        if (e.touches.length == 1) {
          //设置触摸起始点水平方向位置
          this.startX=e.touches[0].clientX;
        }
        console.log(e,'touchstart------')
      },
      touchend(e,index) {
        console.log(index,'-----')
        if (e.changedTouches.length == 1) {
          //手指移动结束后水平位置
          var endX = e.changedTouches[0].clientX;
          let diff = endX-this.startX;
          if(Math.abs(diff)>20){
            if(diff>0){
              console.log("左滑...");
              if(index==1) { 
                this.marginLeft += 175
                this.currentIndex -= 1
                setTimeout(() => {
                  this.isAnimation = false
                  let list = this.originList
                  // list.pop() 
                  this.list = list.concat(list)
                  this.marginLeft = -(list.length)*183
                  console.log(this.marginLeft,'--',list)
                  this.currentIndex = list.length
                  this.$nextTick(() => {
                    setTimeout(() => {
                      this.isAnimation = true
                    },300)
                  })
                },300)
              } else {
                this.marginLeft += 183
                this.currentIndex -= 1
              }
            }else{
              // this.currentIndex = this.list[this.list.findIndex(item => {return item.id==index})+1].id
              if(index==this.list.length-2) {
                this.marginLeft -= 180
                this.currentIndex += 1
                setTimeout(() => {
                  this.isAnimation = false
                  let list = this.originList
                  // list.pop() 
                  this.list = list.concat(list)
                  this.marginLeft = -(list.length-2)*180
                  console.log(this.marginLeft,'--',list)
                  this.currentIndex = list.length-2
                  this.$nextTick(() => {
                    setTimeout(() => {
                      this.isAnimation = true
                    },300)
                  })
                },300)
              } else {
                this.marginLeft -= 182
                this.currentIndex += 1
              }
              console.log("右滑...");
            }
            // if(index == 0) {
            //  this.list.unshift(this.list[this.list.length-1])
            //  this.list.pop()
            // }
            // console.log('--------',this.marginLeft)
          }
        }
        console.log(e,'touchend------')
      }
    }
  }
</script>
<style>
</style>

效果图


相关文章
|
6月前
|
XML 数据格式
美团抢单辅助器app,美团众包抢单辅助脚本,骑手自动抢高价单插件
这是一段关于美团骑手抢单辅助脚本的介绍。使用该脚本可设置最高与最低价格、延迟时间等参数,通过自动化检测和抢单功能帮助骑手提高收入。
|
XML Java Android开发
Android Studio App开发实战项目之广告轮播(附源码 可用于大作业)
Android Studio App开发实战项目之广告轮播(附源码 可用于大作业)
703 1
|
XML Java Android开发
Android Studio App开发中多线程的讲解与实现新闻轮播滚动实战(附源码 超详细必看)
Android Studio App开发中多线程的讲解与实现新闻轮播滚动实战(附源码 超详细必看)
203 0
|
移动开发 小程序
外卖霸王餐系统程序 美团/饿了么霸王餐系统,支持小程序/APP/H5/公众号
微客云免费提供外卖霸王餐系统,支持分站、运营商、商家后台、独立域名,自定义品牌,自主收款。
351 0
|
监控 iOS开发
APP - APP监控软件,美团 24 小时不间断定位上热搜
APP - APP监控软件,美团 24 小时不间断定位上热搜
443 0
APP - APP监控软件,美团 24 小时不间断定位上热搜
|
2月前
|
缓存 移动开发 JavaScript
如何优化UniApp开发的App的启动速度?
如何优化UniApp开发的App的启动速度?
538 139
|
2月前
|
移动开发 JavaScript weex
UniApp开发的App在启动速度方面有哪些优势和劣势?
UniApp开发的App在启动速度方面有哪些优势和劣势?
344 137
|
2月前
|
数据采集 JavaScript 前端开发
开发比分App?你缺的不是程序员
开发体育比分App,关键不在代码,而在懂体育、懂数据、懂用户。明确定位、理清需求、选好数据源,再找专业的产品、数据与技术人才协同,才能少走弯路。程序员最后入场,效率最高。
227 154
|
3月前
|
移动开发 小程序 Android开发
基于 uni-app 开发的废品回收类多端应用功能与界面说明
本文将对一款基于 uni-app 开发的废品回收类多端应用,从多端支持范围、核心功能模块及部分界面展示进行客观说明,相关资源信息也将一并呈现。
162 0

热门文章

最新文章