vue實現(xiàn)拖動左側(cè)導(dǎo)航欄變大變小
更新時間:2022年03月30日 10:02:00 作者:牽手北京99
這篇文章主要為大家詳細介紹了vue實現(xiàn)拖動左側(cè)導(dǎo)航欄變大變小,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue實現(xiàn)拖動左側(cè)導(dǎo)航欄變大變小的具體代碼,供大家參考,具體內(nèi)容如下
<template> ? <div> ? ? <div class="top">頂部導(dǎo)航</div> ? ? <div id="left"> ? ? ? <div id="menu"> ? ? ? ? <span>左側(cè)側(cè)邊欄</span> ? ? ? </div> ? ? ? <div id="drap-line"></div> ? ? </div> ? ? <div id="right"> ? ? ? 右邊的div ? ? </div> ? </div> </template>
<style type="text/css"> ? * {margin: 0;padding: 0;} ? ? html,body {height: 100%;text-align: center;} ? ? body {position: relative;} ? ? .top {width: 100%;height: 88px;background-color: #ccc;} ? ? #left {position: absolute;top: 88px;right: 0;bottom: 0;left: 0;width: 220px;} ? ? #menu {width: 100%;height: 100%;background-color: red;} ? ? #drap-line {position: absolute;top: 0;right: 0;width: 4px;height: 100%;background-color: #999;cursor: e-resize;} ? ? #right {position: absolute;top: 88px;right: 0;bottom: 0;left: 220px;} </style> <script> export default { ? mounted() { ? ? //獲取dom ? ? var drapLine = document.getElementById('drap-line'); ? ? var left = document.getElementById('left'); ? ? var right = document.getElementById('right'); ? ? //設(shè)置最大/最小寬度 ? ? var max_width = 600, ? ? ? min_width = 100; ? ? //記錄鼠標相對left盒子x軸位置 ? ? var mouse_x = 0; ? ? var history_width = localStorage.getItem('sliderWidth'); ? ? if (history_width) { ? ? ? left.style.width = history_width; ? ? ? right.style.left = history_width; ? ? } ? ? //綁定鼠標按下事件 ? ? drapLine.onmousedown = function (e) { ? ? ? var e = e || window.event; ? ? ? //阻止默認事件 ? ? ? e.preventDefault(); ? ? ? mouse_x = e.clientX - left.offsetWidth; ? ? ? document.onmousemove = function (e) { ? ? ? ? var e = e || window.event; ? ? ? ? var left_width = e.clientX - mouse_x; ? ? ? ? left_width = left_width < min_width ? min_width : left_width; ? ? ? ? left_width = left_width > max_width ? max_width : left_width; ? ? ? ? left.style.width = left_width + 'px'; ? ? ? ? right.style.left = left_width + 'px'; ? ? ? }; ? ? ? document.onmouseup = function (e) { ? ? ? ? document.onmousemove = null; ? ? ? ? document.onmouseup = null; ? ? ? ? //localStorage設(shè)置 ? ? ? ? localStorage.setItem('sliderWidth', left.style.width) ? ? ? }; ? ? } ? }, ? methods: { ? ?? ? }, ? watch: { ? ?? ? }, ? data() { ? ? return { ? ? ?? ? ? } ? } } </script>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- vue實現(xiàn)圖片拖動排序
- vue實現(xiàn)移動端拖動排序
- 基于vue-draggable 實現(xiàn)三級拖動排序效果
- vue2 拖動排序 vuedraggable組件的實現(xiàn)
- vue Draggable實現(xiàn)拖動改變順序
- vue實現(xiàn)拖動調(diào)整左右兩側(cè)容器大小
- vue+mousemove實現(xiàn)鼠標拖動功能(拖動過快失效問題解決方法)
- VUE實現(xiàn)可隨意拖動的彈窗組件
- Vue 實現(xiàn)拖動滑塊驗證功能(只有css+js沒有后臺驗證步驟)
- Vue中使用elementui與Sortable.js實現(xiàn)列表拖動排序
相關(guān)文章
vue?parseHTML?函數(shù)源碼解析AST基本形成
這篇文章主要為大家介紹了vue?parseHTML?函數(shù)源碼解析AST基本形成,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-07-07