vue實(shí)現(xiàn)拖動(dòng)左側(cè)導(dǎo)航欄變大變小
更新時(shí)間:2022年03月30日 10:02:00 作者:牽手北京99
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)拖動(dòng)左側(cè)導(dǎo)航欄變大變小,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了vue實(shí)現(xiàn)拖動(dòng)左側(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;
? ? //記錄鼠標(biāo)相對(duì)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;
? ? }
? ? //綁定鼠標(biāo)按下事件
? ? drapLine.onmousedown = function (e) {
? ? ? var e = e || window.event;
? ? ? //阻止默認(rèn)事件
? ? ? 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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- vue實(shí)現(xiàn)圖片拖動(dòng)排序
- vue實(shí)現(xiàn)移動(dòng)端拖動(dòng)排序
- 基于vue-draggable 實(shí)現(xiàn)三級(jí)拖動(dòng)排序效果
- vue2 拖動(dòng)排序 vuedraggable組件的實(shí)現(xiàn)
- vue Draggable實(shí)現(xiàn)拖動(dòng)改變順序
- vue實(shí)現(xiàn)拖動(dòng)調(diào)整左右兩側(cè)容器大小
- vue+mousemove實(shí)現(xiàn)鼠標(biāo)拖動(dòng)功能(拖動(dòng)過快失效問題解決方法)
- VUE實(shí)現(xiàn)可隨意拖動(dòng)的彈窗組件
- Vue 實(shí)現(xiàn)拖動(dòng)滑塊驗(yàn)證功能(只有css+js沒有后臺(tái)驗(yàn)證步驟)
- Vue中使用elementui與Sortable.js實(shí)現(xiàn)列表拖動(dòng)排序
相關(guān)文章
vue使用transition組件動(dòng)畫效果的實(shí)例代碼
這篇文章主要介紹了vue使用transition組件動(dòng)畫效果的實(shí)例代碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01
vite+ts vite.config.ts使用path報(bào)錯(cuò)問題及解決
這篇文章主要介紹了vite+ts vite.config.ts使用path報(bào)錯(cuò)問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10
Vue3.0中的monorepo管理模式的實(shí)現(xiàn)
這篇文章主要介紹了Vue3.0中的monorepo管理模式的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10

