• 拖拽(高度自定义)


    在这里插入图片描述

    思路:
    监听鼠标按下事件,监听在移动时计算它的高度和上面div盒子的高度
    
    • 1
    • 2

    demo

    <template>
      <div style="width: 100%;">
        <div
          ref="DrawerBody"
          class="drawer-body"
        >
          <div>11</div>
          <div>11</div>
          <div>11</div>
          <div>11</div>
          <div>11</div>
          <div>11</div>
          <div>11</div>
          <div>11</div>
          <div>11</div>
          <div>11</div>
          <div>11</div>
          <div>11</div>
          <div>11</div>
        </div>
        <div
          ref="DrawerBottom"
          class="drawer-bottom"
        >
          <div
            ref="DrawerBottomBar"
            class="drawer-bottom-bar"
          >
            <div class="drawer-bottom-bar-true" />
          </div>
          <div class="drawer-bottom-body">
            1111
          </div>
        </div>
      </div>
    </template>
    <script lang="ts" setup>
    
    import { onMounted, ref } from 'vue'
    
    const DrawerBottomBar = ref<any>(null)
    const DrawerBottom = ref<any>(null)
    const DrawerBody = ref<any>(null)
    onMounted(() => {
      DrawerBottomBar.value.onmousedown = (e: any) => {
        const oldHeight = DrawerBottom.value.offsetHeight
        const startY = e.clientY
        document.onmousemove = (e) => {
          console.log(e)
          // 当前鼠标Y值
          const endY = e.clientY
          // 当前鼠标在Y轴移动的距离
          const distance = endY - startY
          // left-top当前高度
          const newHeight = oldHeight - distance
          // 设置dom样式
          DrawerBottom.value.style.height = `${newHeight}px`
    
          DrawerBody.value.style['padding-bottom'] = `${newHeight}px`
        }
        document.onmouseup = () => {
          document.onmousemove = null
          document.onmouseup = null
        }
        return false
      }
    })
    </script>
      <style scoped lang="scss">
      .drawer {
       position: relative;
       &-body {
        background: #fafafa;
        padding: 0 24px;
        width: 100%;
        font-family: "Inter";
        height: calc(100vh - 86px);
        overflow: auto;
        &::-webkit-scrollbar {
         display: none; /* Chrome Safari */
        }
       }
       &-bottom {
        width: 100%;
        position: absolute;
        z-index: 10;
        bottom: 0;
        background: #fff;
        height: 360px;
        border-top: 1px solid #e5e6eb;
        box-shadow: 0px -4px 12px rgba(0, 0, 0, 0.12);
        &-bar {
         &-true {
          height: 4px;
          border-radius: 4px;
          background: rgba(0, 0, 0, 0.32);
         }
         cursor: ns-resize;
         position: absolute;
         left: 50%;
         margin-left: -20%;
         top: -20px;
         width: 40%;
         padding: 10px 0;
        }
       }
      }
      </style>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
  • 相关阅读:
    nodejs开发环境搭建
    普通人下场全球贸易,新一轮结构性机会浮出水面
    Feign的简介及使用
    Java 是什么?Java 的特性、编程环境
    数据挖掘与分析课程笔记(Chapter 21)
    ASEMI肖特基二极管MBR15200FAC参数,MBR15200FAC图片
    java计算机毕业设计海南自贸港知识学习与测试源码+mysql数据库+系统+lw文档+部署
    SpringBoot项目Redis使用
    解决TensorRT加速推理SDXL出现黑图问题
    【链表OJ】一、移除链表元素
  • 原文地址:https://blog.csdn.net/weixin_43909743/article/details/127748600