国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Vue3中div自由拖拽寬度和高度。

這篇具有很好參考價值的文章主要介紹了Vue3中div自由拖拽寬度和高度。。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Vue3中我們會遇到自由拖拽寬度和高度的頁面需求,查看很多方法都無法滿足當前需求。下面是我們Vue3版本的代碼,非常簡單主要構想說粗發(fā)拖拽方法,把所需要的div的高寬進行拖拽位置進行監(jiān)聽來加減自身div的px值。直接復制粘貼就可以實現(xiàn)效果。根據(jù)自己需求更改即可投入使用,非常方便快捷。(本人文章全都是免費開源,拒絕收費。構建果然免費共享技術環(huán)境)

<template>
  <div class="Drag2">
    <div class="box" ref="box">
      <div class="left">
        <!--左側(cè)div內(nèi)容-->
      </div>
      <div class="resize" title="左右側(cè)邊欄">?</div>
      <div class="mid">
        <!--右側(cè)div內(nèi)容-->

        <div class="topBox">
          <!--右上div內(nèi)容-->
        </div>
        <div title="上下側(cè)邊欄" class="move">?</div>
        <div class="downBox">
          <!--右下div內(nèi)容-->
        </div>
      </div>
    </div>
  </div>
</template>


<script setup lang="ts">
import { onMounted, ref } from "vue";

onMounted(() => {
  dragControllerLR();
  dragControllerUD();
});
// 左右拖動事件
function dragControllerLR() {
  var resize = document.getElementsByClassName("resize");
  var left = document.getElementsByClassName("left");
  var mid = document.getElementsByClassName("mid");
  var box = document.getElementsByClassName("box");
  console.log(document.getElementsByClassName("resize"));
  for (let i = 0; i < resize.length; i++) {
    // 鼠標按下事件
    resize[i].onmousedown = function (e) {
      //顏色改變提醒
      resize[i].style.background = "#818181";
      var startX = e.clientX;
      resize[i].left = resize[i].offsetLeft;
      // 鼠標拖動事件
      document.onmousemove = function (e) {
        var endX = e.clientX;
        var moveLen = resize[i].left + (endX - startX); // (endx-startx)=移動的距離。resize[i].left+移動的距離=左邊區(qū)域最后的寬度
        var maxT = box[i].clientWidth - resize[i].offsetWidth; // 容器寬度 - 左邊區(qū)域的寬度 = 右邊區(qū)域的寬度

        if (moveLen < 50) moveLen = 50; // 左邊區(qū)域的最小寬度為50px
        if (moveLen > maxT - 150) moveLen = maxT - 150; //右邊區(qū)域最小寬度為150px

        resize[i].style.left = moveLen; // 設置左側(cè)區(qū)域的寬度

        for (let j = 0; j < left.length; j++) {
          left[j].style.width = moveLen + "px";
          mid[j].style.width = box[i].clientWidth - moveLen - 10 + "px";
        }
      };
      // 鼠標松開事件
      // eslint-disable-next-line no-unused-vars
      document.onmouseup = function (evt) {
        //顏色恢復
        resize[i].style.background = "#d6d6d6";
        document.onmousemove = null;
        document.onmouseup = null;
        resize[i].releaseCapture && resize[i].releaseCapture(); //當你不在需要繼續(xù)獲得鼠標消息就要應該調(diào)用ReleaseCapture()釋放掉
      };
      resize[i].setCapture && resize[i].setCapture(); //該函數(shù)在屬于當前線程的指定窗口里設置鼠標捕獲
      return false;
    };
  }
}
// 上下拖動事件
function dragControllerUD() {
  var resize = document.getElementsByClassName("move");
  var topBox = document.getElementsByClassName("topBox");
  var downBox = document.getElementsByClassName("downBox");
  var box = document.getElementsByClassName("mid");
  console.log(document.getElementsByClassName("move"));
  for (let i = 0; i < resize.length; i++) {
    // 鼠標按下事件
    resize[i].onmousedown = function (e) {
      console.log(resize[i].top);
      //顏色改變提醒
      resize[i].style.background = "#818181";
      var startY = e.clientY;
      resize[i].top = resize[i].offsetTop;
      // 鼠標拖動事件
      document.onmousemove = function (e) {
        var endY = e.clientY;
        var moveLen = resize[i].top + (endY - startY); // (endY - startY)=移動的距離。resize[i].top+移動的距離=上邊區(qū)域最后的高度
        var maxT = box[i].clientHeight - resize[i].offsetHeight; // 容器高度 - 上邊區(qū)域的高度 = 下邊區(qū)域的高度

        if (moveLen < 50) moveLen = 50; // 上邊區(qū)域的最小高度為50px
        if (moveLen > maxT - 150) moveLen = maxT - 150; //下邊區(qū)域最小高度為150px

        resize[i].style.top = moveLen; // 設置上邊區(qū)域的高度

        for (let j = 0; j < topBox.length; j++) {
          topBox[j].style.height = moveLen + "px";
          downBox[j].style.height = box[i].clientHeight - moveLen - 10 + "px";
        }
      };
      // 鼠標松開事件
      document.onmouseup = function () {
        //顏色恢復
        resize[i].style.background = "#d6d6d6";
        document.onmousemove = null;
        document.onmouseup = null;
        resize[i].releaseCapture && resize[i].releaseCapture(); //當你不在需要繼續(xù)獲得鼠標消息就要應該調(diào)用ReleaseCapture()釋放掉
      };
      resize[i].setCapture && resize[i].setCapture(); //該函數(shù)在屬于當前線程的指定窗口里設置鼠標捕獲
      return false;
    };
  }
}
</script>
<style>
/* 拖拽相關樣式 */

/*包圍div樣式*/
.box {
  width: 100vh;
  height: calc(98vh - 10px);
  margin: 1% 0px;
  overflow: hidden;
  box-shadow: -1px 9px 10px 3px rgba(0, 0, 0, 0.11);
}
/*左側(cè)div樣式*/
.left {
  width: calc(32% - 10px); /*左側(cè)初始化寬度*/
  height: 100%;
  background: #71ad88;
  float: left;
}
/* 拖拽區(qū)div樣式 */
.resize {
  cursor: w-resize;
  float: left;
  position: relative;
  top: 45%;
  background-color: #d6d6d6;
  border-radius: 5px;
  margin-top: -10px;
  width: 10px;
  height: 50px;
  background-size: cover;
  background-position: center;
  /*z-index: 99999;*/
  font-size: 32px;
  color: white;
}

/*拖拽區(qū)鼠標懸停樣式*/
.move:hover {
  color: #444444;
}
/*右側(cè)div'樣式*/
.mid {
  float: left;
  width: 68%; /*右側(cè)初始化寬度*/
  height: 100%;
  background: #f3f3f3;
  box-shadow: -1px 4px 5px 3px rgba(0, 0, 0, 0.11);
  /*上方div'樣式*/
  .topBox {
    height: 60%;
    background-color: #3ff53f;
    display: flex;
  }
  /*下方div'樣式*/
  .downBox {
    height: calc(40% - 10px);
    background-color: #f0fd35;
    display: flex;
  }
  /* 拖拽區(qū)div樣式 */
  .move {
    cursor: s-resize;
    width: 50px;
    height: 10px;
    background-color: #d6d6d6;
    margin: 0 auto;
    border-radius: 5px;
    text-align: center;
    line-height: 3px;
    font-size: 32px;
    color: white;
  }
  /*拖拽區(qū)鼠標懸停樣式*/
  .move:hover {
    color: #444444;
  }
}
</style>

效果圖如下:

Vue3中div自由拖拽寬度和高度。

下面希望各位大哥支持一下我開發(fā)的小程序,萘兔小程序用戶始終堅持免費提供用戶使用的一個小程序,提成程序免費便利于群眾,服務群眾的宗旨。同時不斷提高自身的能力和了解用戶需求,開拓自身的程序視野,快速提高自我技術,未編程共享繼續(xù)提供更多的免費代碼交流環(huán)境。點擊一下增加一下我的用戶量。如有建議可以私信我非常感激。

Vue3中div自由拖拽寬度和高度。

Vue3介紹(不用理會)
vue3.0帶來了什么
1.性能的提升
打包大小減少41%
初次渲染快55%,更新渲染塊133%
內(nèi)存減少54%
........
2.源碼的升級
使用Proxy代替defineProperty實現(xiàn)響應式
重寫虛擬DOM的實現(xiàn)和Tree-Sharking
......
3.擁抱TypeScript
vue3.0更好的支持TypeScript
4.新的特性
Composition API(組合api)

。 setup配置

。ref與reactive

。watch與watchEffect

。 provide和inject

。 .......

新的內(nèi)置組件

。 Fragment

。Teleport

。Suspense

其他改變

。新的生命周期鉤子

。data選項應始終被聲明為一個函數(shù)

。移除keyCode支持作為v-on的修飾符文章來源地址http://www.zghlxwxcb.cn/news/detail-486720.html

到了這里,關于Vue3中div自由拖拽寬度和高度。的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • vue拖拽改變寬度

    vue拖拽改變寬度

    ?1.封裝組件ResizeBox.vue ?2.組件中使用

    2024年02月14日
    瀏覽(18)
  • vue如何實現(xiàn)實時監(jiān)聽頁面寬度高度變化

    運用的主要技術:watch監(jiān)聽 話不多說直接上代碼,自行研究

    2024年02月11日
    瀏覽(26)
  • 如何動態(tài)設置vue組件的寬度和高度?

    如何動態(tài)設置vue組件的寬度和高度?

    在組件最外層加上div 給div加上屬性:style=“{ height: toggleHeight ? toggleHeight : ‘2000px’, width: toggleWidth ? toggleWidth : ‘1188px’ }” 使用js修改toggleHeight 和 toggleWidth 的值 實現(xiàn)動態(tài)修改寬高 例 在父組件中動態(tài)修改子組件的寬度 auditInformation子組件中 index父組件中

    2024年02月12日
    瀏覽(22)
  • Vue uniapp實現(xiàn)圖片寬度100%、高度自適應的效果

    在Uniapp中,我們可以使用image組件來加載圖片,而想要實現(xiàn)圖片寬度100%、高度自適應的效果,可以通過以下步驟實現(xiàn): 首先,在image組件上設置mode屬性為widthFix,表示按照圖片的寬度等比縮放,并保證圖片寬度為100%。 接著,在image組件上設置style屬性,為圖片設置高度自適應

    2024年02月15日
    瀏覽(133)
  • vue實現(xiàn)鼠標拖拽div左右移動的功能

    vue實現(xiàn)鼠標拖拽div左右移動的功能

    直接代碼: 這部分區(qū)域可以鼠標拖拽左右滾動

    2024年02月03日
    瀏覽(95)
  • vue實現(xiàn)在頁面拖拽放大縮小div并顯示鼠標在div的坐標

    vue實現(xiàn)在頁面拖拽放大縮小div并顯示鼠標在div的坐標

    實現(xiàn)在一個指定區(qū)域拖拽div,并可以放大縮小,同時顯示鼠標在該div里的坐標,如圖可示 縮小并拖動 js代碼 css

    2024年02月05日
    瀏覽(229)
  • Vue教程:如何使用Div標簽實現(xiàn)單選框與多選框按鈕以便我們隨意調(diào)整樣式

    Vue教程:如何使用Div標簽實現(xiàn)單選框與多選框按鈕以便我們隨意調(diào)整樣式

    前言: 在寫Vue項目時,我們經(jīng)常會用到單選框以及復選框,以往我們常用的是Element里面的單選框以及復選框,但是呢這里面的選框都不容易調(diào)整,假如我們需要不同的樣式以及大小,就很難去實現(xiàn)想要的結果,本章教程就為大家講解,如何使用div標簽去實現(xiàn)單選,多選的這

    2024年01月18日
    瀏覽(28)
  • vue3項目中,點擊某個div以外的區(qū)域,將這個div隱藏

    使用 @click 來監(jiān)聽 div 的點擊事件,并通過 v-if 來控制 div 的顯示與隱藏。在組件的 mounted 鉤子函數(shù)中,通過 document.addEventListener 添加了一個點擊事件監(jiān)聽器,用于監(jiān)聽整個頁面的點擊事件。當點擊事件發(fā)生時,會調(diào)用 handleClickOutside 方法來檢查是否需要隱藏 div。最后,在組件

    2024年02月13日
    瀏覽(17)
  • Vue3通過 directive 實現(xiàn) el-dropdown下拉菜單項最小寬度等于內(nèi)容寬度

    Vue3通過 directive 實現(xiàn) el-dropdown下拉菜單項最小寬度等于內(nèi)容寬度

    原始效果 最終效果 el-dropdown API 并不提供配置項讓我們實現(xiàn)下拉菜單項最小寬度等于內(nèi)容寬度,但我們能發(fā)現(xiàn)它提供了 popper-class 用于自定義浮層類名。 那么我們是否可以通過 popper-class 配置項來實現(xiàn)想要的功能呢?或者通過 el-dropdown-menu style=\\\"min-width: 100px;\\\" 這種形式進行最小

    2024年02月09日
    瀏覽(87)
  • vue3 拖拽插件 Vue3DraggableResizable

    Vue3DraggableResizable 拖拽插件的官方文檔 一、Vue3DraggableResizable 的屬性和事件 屬性 類型 默認值 功能描述 示例 initW Number null 設置初始寬度(px) Vue3DraggableResizable :initW=“100” / initH Number null 設置初始高度(px) Vue3DraggableResizable :initH=“100” / w Number 0 組件的當前寬度(px),你

    2024年02月03日
    瀏覽(17)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包