Vue實(shí)現(xiàn)拖拽式分割布局
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)拖拽式分割布局的具體代碼,供大家參考,具體內(nèi)容如下
示例展示
代碼
特地寫了一個demo代碼,可以直接復(fù)制下來運(yùn)行
<!DOCTYPE html> <html lang="en"> <head> ? ? <meta charset="UTF-8"> ? ? <meta name="viewport" content="width=device-width, initial-scale=1.0"> ? ? <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> ? ? <title>Document</title> </head> <body> <div id="app"> ? <div class='container' id='container'> ? ? <div id='top' class='top'>top</div> ? ? <div id='bar' class='bar'></div> ? ? <div id='bottom' class='bottom'>bottom</div> ? </div> </div> <script> var app = new Vue({ ? ? el: '#app', ? ? data: { ? ? }, ? ? mounted(){ ? ? ? this.dragChangeHeight('bar','top') ? ? }, ? ? methods:{ ? ? ? dragChangeHeight(drag, panel) { ? ? ? ? var dragEl = document.getElementById(drag) ? ? ? ? var panelEl = document.getElementById(panel) ? ? ? ? dragEl.onmousedown = function(ev) { ? ? ? ? ? var disH = panelEl.offsetHeight ? ? ? ? ? var disY = ev.clientY ? ? ? ? ? var disT = panelEl.offsetTop ? ? ? ? ? var b = '' ? ? ? ? ?? ? ? ? ? ? document.onmousemove = function(ev) { ? ? ? ? ? ? panelEl.style.height = disH + (ev.clientY - disY) + 'px' ? ? ? ? ? ? // panelEl.style.top = disL - (ev.clientY - disY) + 'px' ? ? ? ? ? } ? ? ? ? ? document.onmouseup = function() { ? ? ? ? ? ? document.onmousemove = document.onmouseup = null ? ? ? ? ? } ? ? ? ? ? return false ? ? ? ? } ? ? ? }, ? ? ? dragChangeWidth(drag, panel) { ? ? ? ? var dragEl = document.getElementById(drag) ? ? ? ? var panelEl = document.getElementById(panel) ? ? ? ? dragEl.onmousedown = function(ev) { ? ? ? ? ? var disW = panelEl.offsetWidth ? ? ? ? ? var disX = ev.clientX ? ? ? ? ? var disL = panelEl.offsetLeft ? ? ? ? ? var b = '' ? ? ? ? ? document.onmousemove = function(ev) { ? ? ? ? ? ? ? panelEl.style.width = disW + (ev.clientX - disX) + 'px' ? ? ? ? ? ? ? // panelEl.style.left = disL - (ev.clientX - disX) + 'px' ? ? ? ? ? } ? ? ? ? ? document.onmouseup = function() { ? ? ? ? ? ? document.onmousemove = document.onmouseup = null ? ? ? ? ? } ? ? ? ? ? return false ? ? ? ? } ? ? ? }, ? ? } }) </script> <style> ? body{ ? ? margin: 0; ? } ? .container{ ? ? /* padding: 20px; */ ? ?? ? ? height: 90vh; ? ? width: 90vw; ? ? display: flex; ? ? flex-direction: column; ? } ? .top{ ? ? width: 100%; ? ? height: 300px; ? ? background-color: blue; ? } ? .bar{ ? ? width: 100%; ? ? height: 10px; ? ? cursor: n-resize; ? ? background-color: black; ? } ? .bottom{ ? ? width: 100%; ? ? flex: auto; ? ? background-color: red; ? } </style> </body> </html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vscode中vue代碼提示與補(bǔ)全沒反應(yīng)解決(vetur問題)
這篇文章主要給大家介紹了關(guān)于vscode中vue代碼提示與補(bǔ)全沒反應(yīng)解決(vetur問題)的相關(guān)資料,文中通過圖文將解決的方法介紹的非常詳細(xì),需要的朋友可以參考下2023-03-03vue-router之路由鉤子函數(shù)應(yīng)用小結(jié)
vue-router提供的導(dǎo)航鉤子主要用來攔截導(dǎo)航,讓它完成跳轉(zhuǎn)或取消,本文主要介紹了vue-router之路由鉤子函數(shù)應(yīng)用小結(jié),具有一定的參考價值,感興趣的可以了解一下2024-01-01vue如何實(shí)現(xiàn)關(guān)閉對話框后刷新列表
這篇文章主要介紹了vue如何實(shí)現(xiàn)關(guān)閉對話框后刷新列表,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04使用vue實(shí)現(xiàn)通過變量動態(tài)拼接url
這篇文章主要介紹了使用vue實(shí)現(xiàn)通過變量動態(tài)拼接url,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07Vue中watch與watchEffect的區(qū)別詳細(xì)解讀
這篇文章主要介紹了Vue中watch與watchEffect的區(qū)別詳細(xì)解讀,watch函數(shù)與watchEffect函數(shù)都是監(jiān)聽器,在寫法和用法上有一定區(qū)別,是同一功能的兩種不同形態(tài),底層都是一樣的,需要的朋友可以參考下2023-11-11vue 使用lodash實(shí)現(xiàn)對象數(shù)組深拷貝操作
這篇文章主要介紹了vue 使用lodash實(shí)現(xiàn)對象數(shù)組深拷貝操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09