• 拖拽(高度自定义)


    在这里插入图片描述

    思路:
    监听鼠标按下事件,监听在移动时计算它的高度和上面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
  • 相关阅读:
    Vue 入门案例剖析
    LInux系统编程(3)
    【算法】平衡二叉树
    freeRTOS学习day4-中断使用消息队列
    关于大型客户端项目的思考
    昇思25天学习打卡营第15天|基于 MindSpore 实现 BERT 对话情绪识别
    浅谈当下7个网页设计趋势 优漫动游
    Web前端学习笔记6(align-items,align-content,flex-flow,flex,align-self,order)
    在UE4(Unreal Engine4)中安装 Quixel Bridge Megascans bridget插件
    WiFi网络分析工具Airtool for Mac
  • 原文地址:https://blog.csdn.net/weixin_43909743/article/details/127748600