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

概要

使用百度地图、各种单车APP时,对地图上的滑动面板很感兴趣,于是根据自己的理解实现了一下

之前用的js实现,滑动的时候没有原生好

这一次用的css实现

代码

javascript 复制代码
<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>

效果图

在这里插入图片描述

相关推荐
ShenJLLL5 小时前
vue部分知识点.
前端·javascript·vue.js·前端框架
CappuccinoRose7 小时前
CSS 语法学习文档(十九)
前端·css·属性·flex·grid·学习资源·格式化上下文
HelloReader14 小时前
Tauri 2 创建项目全流程create-tauri-app 一键脚手架 + Tauri CLI 手动接入
前端·javascript·vue.js
哆啦A梦158814 小时前
Vue3魔法手册 作者 张天禹 016_vue3中一些特定用法介绍
前端·vue.js·typescript
计算机毕设VX:Fegn089516 小时前
计算机毕业设计|基于springboot + vue连锁门店管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
麦麦大数据17 小时前
F071_vue+flask基于YOLOv8的实时目标检测与追踪系统
vue.js·yolo·目标检测·flask·vue·视频检测
带你看月亮18 小时前
Vue3解析学习 - handlers 模块
vue.js·学习
肖。354878709419 小时前
html中onclick误区,后续变量会更改怎么办?
android·java·javascript·css·html
暴力袋鼠哥19 小时前
SpringBoot+Vue实战:多模态疾病初筛与护理建议系统(含泳道图+时序图+完整后端代码)
vue.js·spring boot·后端
用户57573033462419 小时前
🎨 CSS变量彻底指南:从入门到精通,99%的人不知道的动态样式魔法!
css