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>

效果图


相关文章
|
5月前
|
XML Java Android开发
Android Studio App开发实战项目之广告轮播(附源码 可用于大作业)
Android Studio App开发实战项目之广告轮播(附源码 可用于大作业)
164 1
|
5月前
|
XML Java Android开发
Android Studio App开发中多线程的讲解与实现新闻轮播滚动实战(附源码 超详细必看)
Android Studio App开发中多线程的讲解与实现新闻轮播滚动实战(附源码 超详细必看)
56 0
|
监控 iOS开发
APP - APP监控软件,美团 24 小时不间断定位上热搜
APP - APP监控软件,美团 24 小时不间断定位上热搜
296 0
APP - APP监控软件,美团 24 小时不间断定位上热搜
|
5天前
|
移动开发 Android开发 数据安全/隐私保护
移动应用与系统的技术演进:从开发到操作系统的全景解析随着智能手机和平板电脑的普及,移动应用(App)已成为人们日常生活中不可或缺的一部分。无论是社交、娱乐、购物还是办公,移动应用都扮演着重要的角色。而支撑这些应用运行的,正是功能强大且复杂的移动操作系统。本文将深入探讨移动应用的开发过程及其背后的操作系统机制,揭示这一领域的技术演进。
本文旨在提供关于移动应用与系统技术的全面概述,涵盖移动应用的开发生命周期、主要移动操作系统的特点以及它们之间的竞争关系。我们将探讨如何高效地开发移动应用,并分析iOS和Android两大主流操作系统的技术优势与局限。同时,本文还将讨论跨平台解决方案的兴起及其对移动开发领域的影响。通过这篇技术性文章,读者将获得对移动应用开发及操作系统深层理解的钥匙。
|
9天前
|
XML 移动开发 前端开发
使用duxapp开发 React Native App 事半功倍
对于Taro的壳子,或者原生React Native,都会存在 `android` `ios`这两个文件夹,而在duxapp中,这些文件夹的内容是自动生成的,那么对于需要在这些文件夹中修改的配置内容,例如包名、版本号、新架构开关等,都通过配置文件的方式配置了,而不需要需修改具体的文件
|
9天前
|
存储 开发工具 Android开发
使用.NET MAUI开发第一个安卓APP
【9月更文挑战第24天】使用.NET MAUI开发首个安卓APP需完成以下步骤:首先,安装Visual Studio 2022并勾选“.NET Multi-platform App UI development”工作负载;接着,安装Android SDK。然后,创建新项目时选择“.NET Multi-platform App (MAUI)”模板,并仅针对Android平台进行配置。了解项目结构,包括`.csproj`配置文件、`Properties`配置文件夹、平台特定代码及共享代码等。
|
1月前
|
Web App开发 Java 视频直播
FFmpeg开发笔记(四十九)助您在毕业设计中脱颖而出的几个流行APP
对于软件、计算机等专业的毕业生,毕业设计需实现实用软件或APP。新颖的设计应结合最新技术,如5G时代的音视频技术。示例包括: 1. **短视频分享APP**: 集成FFmpeg实现视频剪辑功能,如添加字幕、转场特效等。 2. **电商购物APP**: 具备直播带货功能,使用RTMP/SRT协议支持流畅直播体验。 3. **同城生活APP**: 引入WebRTC技术实现可信的视频通话功能。这些应用不仅实用,还能展示开发者紧跟技术潮流的能力。
69 4
FFmpeg开发笔记(四十九)助您在毕业设计中脱颖而出的几个流行APP
|
28天前
|
移动开发 小程序 JavaScript
uni-app开发微信小程序
本文详细介绍如何使用 uni-app 开发微信小程序,涵盖需求分析、架构思路及实施方案。主要功能包括用户登录、商品列表展示、商品详情、购物车及订单管理。技术栈采用 uni-app、uView UI 和 RESTful API。文章通过具体示例代码展示了从初始化项目、配置全局样式到实现各页面组件及 API 接口的全过程,并提供了完整的文件结构和配置文件示例。此外,还介绍了微信授权登录及后端接口模拟方法,确保项目的稳定性和安全性。通过本教程,读者可快速掌握使用 uni-app 开发微信小程序的方法。
57 3
|
2月前
|
Web App开发 Android开发
FFmpeg开发笔记(四十六)利用SRT协议构建手机APP的直播Demo
实时数据传输在互联网中至关重要,不仅支持即时通讯如QQ、微信的文字与图片传输,还包括音视频通信。一对一通信常采用WebRTC技术,如《Android Studio开发实战》中的App集成示例;而一对多的在线直播则需部署独立的流媒体服务器,使用如SRT等协议。SRT因其优越的直播质量正逐渐成为主流。本文档概述了SRT协议的使用,包括通过OBS Studio和SRT Streamer进行SRT直播推流的方法,并展示了推流与拉流的成功实例。更多细节参见《FFmpeg开发实战》一书。
43 1
FFmpeg开发笔记(四十六)利用SRT协议构建手机APP的直播Demo
|
2月前
|
Web App开发 5G Linux
FFmpeg开发笔记(四十四)毕业设计可做的几个拉满颜值的音视频APP
一年一度的毕业季来临,计算机专业的毕业设计尤为重要,不仅关乎学业评价还积累实战经验。选择紧跟5G技术趋势的音视频APP作为课题极具吸引力。这里推荐三类应用:一是融合WebRTC技术实现视频通话的即时通信APP;二是具备在线直播功能的短视频分享平台,涉及RTMP/SRT等直播技术;三是具有自定义动画特效及卡拉OK歌词字幕功能的视频剪辑工具。这些项目不仅技术含量高,也符合市场需求,是毕业设计的理想选择。
68 6
FFmpeg开发笔记(四十四)毕业设计可做的几个拉满颜值的音视频APP
下一篇
无影云桌面