当前位置: 首页 > news >正文

vue + uniapp 实现仿百度地图/高德地图/美团/支付宝 滑动面板 纯css 实现

概要

使用百度地图、各种单车APP时,对地图上的滑动面板很感兴趣,于是根据自己的理解实现了一下
之前用的js实现,滑动的时候没有原生好
这一次用的css实现

代码

<template>
  <view class="container">
    <map
      style="
        position: fixed;
        height: 100%;
        width: 100%;
        top: 0;
        left: 0;
        z-index: 0;
      "
      :enable-scroll="!isPanelTouched"
    ></map>
    <view
      style="
        height: 500rpx;
        width: 100%;
        background-color: rgba(255, 255, 255, 0.8);
        z-index: -1;
      "
    ></view>
    <view
      class="panel"
      @touchstart="onPanelTouchStart"
      @touchend="onPanelTouchEnd"
    >
      <view class="handle"></view>
      <view class="item" v-for="item in 50" :key="item">
        {{ item }}
      </view>
    </view>
    <view
      v-if="isPanelTouched"
      class="mask"
      @touchstart.stop.prevent
      @touchmove.stop.prevent
      @touchend.stop.prevent
    ></view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      isPanelTouched: false
    }
  },
  methods: {
    onPanelTouchStart() {
      this.isPanelTouched = true
    },
    onPanelTouchEnd() {
      this.isPanelTouched = false
    }
  }
}
</script>

<style scoped lang="scss">
.panel {
  position: relative;
  background-color: #fff;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  z-index: 2;
  .handle {
    height: 30px;
    background-color: #eee;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;

    &::after {
      content: '';
      width: 30px;
      height: 3px;
      background-color: #999;
      border-radius: 3px;
    }
  }
  .content {
    height: calc(100% - 30px);
    overflow-y: auto;
  }
  .item {
    text-align: center;
    font-size: 14px;
    color: #333;
    margin-bottom: 10px;
    padding: 10px;
    border-bottom: 1px solid #eee;
  }
}

.mask {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background-color: rgba(0, 0, 0, 0);
}
</style>

效果图

在这里插入图片描述

在这里插入图片描述

http://www.dtcms.com/a/130443.html

相关文章:

  • Matlab个性化绘图第10期—滑珠进度柱状图
  • 富文本编辑器的内容导出html,并保留图片
  • 【第41节】windows的中断与异常及异常处理方式
  • 【第四十周】文献阅读:用于检索-增强大语言模型的查询与重写
  • 精品整理 | 云安全知识证书 (CCSK) v5 备考学习资源汇总
  • Reinforcement Learning-Autonomous car-useful
  • 【数学建模】(智能优化算法)粒子群优化算法(PSO)详解与Python实现
  • 【STM32】STemWin库,使用template API
  • vs2022 pcl1.15.0注意点
  • 实现当文本内容过长时,中间显示省略号...,两端正常展示
  • K8S+Prometheus+Consul+alertWebhook实现全链路服务自动发现与监控、告警配置实战
  • GitHub 趋势日报 (2025年04月12日)
  • 【C++】继承:万字总结
  • 《2025四大AI终极对决:如何用ChatGPT、DeepSeek、通义千问和文心一言提升项目管理效率?》
  • STM32 HAL库SPI读写W25Q128(软件模拟+硬件spi)
  • Python基础总结(四)之元组
  • 计算机视觉6——相机基础
  • (自用)毕业论文格式
  • 文件操作和 IO - 一些具体的使用栗子
  • 动手学深度学习:手语视频在VGG模型中的测试
  • 测试 笔记
  • 【计网】网络交换技术之报文交换(复习自用,了解,重要3)
  • 0x06.Redis 中常见的数据类型有哪些?
  • FutureTask 源码解析
  • 深入剖析 Axios 的 POST 请求:何时使用 qs 处理数据
  • 0基础 | 硬件滤波 C、RC、LC、π型
  • 基于Springboot+Mysql的闲一品(含LW+PPT+源码+系统演示视频+安装说明)
  • [16届蓝桥杯 2025 c++省 B] 水质检测
  • Axure疑难杂症:详解横向菜单左右拖动效果及阈值说明
  • 在Fortran程序中嵌入Lua解释器