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 Java Android开发
Android Studio App开发中多线程的讲解与实现新闻轮播滚动实战(附源码 超详细必看)
Android Studio App开发中多线程的讲解与实现新闻轮播滚动实战(附源码 超详细必看)
36 0
|
6天前
|
XML Java Android开发
Android Studio App开发实战项目之广告轮播(附源码 可用于大作业)
Android Studio App开发实战项目之广告轮播(附源码 可用于大作业)
90 1
|
6天前
|
移动开发 小程序
如何让uni-app开发的H5页面顶部原生标题和小程序的顶部标题不一致?
如何让uni-app开发的H5页面顶部原生标题和小程序的顶部标题不一致?
|
6天前
|
API 数据安全/隐私保护 iOS开发
利用uni-app 开发的iOS app 发布到App Store全流程
利用uni-app 开发的iOS app 发布到App Store全流程
116 3
|
6天前
|
Android开发 开发者 UED
个人开发 App 成功上架手机应用市场的关键步骤
个人开发 App 成功上架手机应用市场的关键步骤
|
6天前
|
开发工具 数据安全/隐私保护 Android开发
【教程】APP 开发后如何上架?
【教程】APP 开发后如何上架?
|
6天前
|
API
uni-app 146朋友圈列表api开发
uni-app 146朋友圈列表api开发
21 0
|
1天前
|
Web App开发 JSON 小程序
苹果app开发apple-app-site-association文件配置
apple-app-site-association 是苹果的配置文件,用于建立app和网站关联,支持Universal Links,使点击网站链接能直接打开相应app内部页面。配置文件为JSON格式,需上传至服务器`.well-known`目录或根目录。通过检查三个链接来测试配置,确保Content-Type为`application/json`。成功配置后,点击链接能在iPhone备忘录或Safari中直接唤起app,但可能有24-48小时延迟。
19 6
|
6天前
|
Web App开发 数据采集 移动开发
开发uniapp过程中对app、微信小程序与h5的webview调试
开发uniapp过程中对app、微信小程序与h5的webview调试
16 1
|
6天前
|
前端开发 Android开发 开发者
【Flutter前端技术开发专栏】Flutter中的混合应用(Hybrid Apps)开发
【4月更文挑战第30天】本文探讨了使用Flutter开发混合应用的方法。混合应用结合Web技术和原生容器,提供快速开发和低成本维护。Flutter,一款现代前端框架,以其插件系统和高性能渲染引擎支持混合应用开发。通过创建Flutter项目、添加平台代码、使用WebView、处理平台间通信以及发布应用,开发者可构建跨平台混合应用。虽然混合应用有性能和用户体验的局限,但Flutter的跨平台兼容性和丰富的插件生态降低了开发成本。开发者应根据项目需求权衡选择。
【Flutter前端技术开发专栏】Flutter中的混合应用(Hybrid Apps)开发