日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

左右滑动栏

發(fā)布時(shí)間:2023/12/13 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 左右滑动栏 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

展示效果圖:

<template><div ref="topBox" class="swiper-in page-container bg-white"><div class="page-body"><drag-box class="drag-box"><div class="relative" :class="{'expend-border':!slideStateX}" :style="{'width': slideStateX? '350px' : '35px'}" ref="sliderLeft"><drag-item v-show="slideStateX">123</drag-item><div v-if="expendX" :class="slideStateX?'close-box-button-x':'open-box-button-x'" @click="slideStateX = !slideStateX"></div><div v-show="!slideStateX" class="arrow-content text-gray-500">展開側(cè)邊欄</div></div><drag-item class="w-4/5 flex-col-box" :resizeShow="false" ref="sliderRight"><div class="flex-auto flex-col-box">123123</div></drag-item></drag-box></div></div> </template><script> import { dragBox, dragItem } from '@/components/common/dragLayouter' export default {components: {dragBox,dragItem},data() {return {expendX: true,slideStateX: true}},watch: {},created(){},methods:{} } </script><style scoped> @import '../../assets/css/basicPageTemplate/basicPageTemplate.css'; .topbox {padding: 1rem;border-bottom: 1px solid #ccc; } </style>

子1

<template><div ref="container" class="d-flex"><slot>默認(rèn)信息</slot><!-- 拖拽條 --><div v-if="resizeShow" class="resize"/></div> </template><script>export default {name: 'dragItem',props: {// 控制拖拽條的是否顯示,默認(rèn)顯示resizeShow: {type: Boolean,default: true}}} </script><style>.d-flex {min-width: 100px;height: 100%;position: relative;}.resize {position: absolute;top: 0;right: 0;width: 4px;height: 100%;cursor: col-resize;background: #e6e6e6;} </style>

子2

<template><div ref='dragBox' class="dragBox"><slot></slot></div> </template><script>export default {name: 'dragBox',data() {return {}},mounted() {this.setDragItemFlex()this.dragControllerDiv()},methods: {// 如果dragItem 沒有定義寬度,則flex=1setDragItemFlex() {const dragBox = this.$refs.dragBoxconst childsLen = dragBox.children.lengthfor (let i = 0; i < childsLen; i++) {const node = dragBox.children[i]if (!node.style.width) {// 如果沒有定義寬度,則flex=1node.style.flex = 1}}},dragControllerDiv() {const resize = document.getElementsByClassName('resize') // 拖拽條// 循環(huán)為每個(gè)拖拽條添加事件for (let i = 0; i < resize.length; i++) {// 鼠標(biāo)按下事件resize[i].addEventListener('mousedown', this.onMouseDown)}},onMouseDown(e) {this.resizeBox = e.targetthis.currentBox = this.resizeBox.parentNode.parentNode// 當(dāng)前盒子this.rightBox = this.getNextElement(this.currentBox)// 當(dāng)前盒子的下個(gè)兄弟節(jié)點(diǎn)if (!this.rightBox) {return}this.curLen = this.currentBox.clientWidththis.otherBoxWidth = this.$refs.dragBox.clientWidth - this.currentBox.clientWidth - this.rightBox.clientWidth // 其他盒子的寬度// 顏色改變提醒// this.resizeBox.style.background = '#818181'this.startX = e.clientXdocument.addEventListener('mousemove', this.onMousemove)document.addEventListener('mouseup', this.onMouseup)},// 獲取下一個(gè)兄弟元素的兼容函數(shù)getNextElement(element) {if (element.nextElementSibling) {return element.nextElementSibling} else {let next = element.nextSibling// 下一個(gè)兄弟節(jié)點(diǎn)while (next && next.nodeType !== 1) { // 有 并且 不是我想要的next = next.nextSibling}return next}},onMousemove(e) {const endX = e.clientXconst moveLen = endX - this.startX // (endx-startx)= 移動(dòng)的距離const CurBoxLen = this.curLen + moveLen // resize[i].left+移動(dòng)的距離=左邊區(qū)域最后的寬度const rightBoxLen = this.$refs.dragBox.clientWidth - CurBoxLen - this.otherBoxWidth // 右側(cè)寬度=總寬度-左側(cè)寬度-其它盒子寬度// 當(dāng)最小寬度時(shí),無法繼續(xù)拖動(dòng)if (CurBoxLen <= 100 || rightBoxLen <= 100) {return}this.currentBox.style.width = CurBoxLen + 'px'// 當(dāng)前盒子的寬度this.resizeBox.style.left = CurBoxLen // 設(shè)置左側(cè)區(qū)域的寬度this.rightBox.style.width = rightBoxLen + 'px'},onMouseup() {// 顏色恢復(fù)// this.resizeBox.style.background = '#d6d6d6'document.removeEventListener('mousedown', this.onMouseDown)document.removeEventListener('mousemove', this.onMousemove)}}} </script><style scoped>.dragBox {width: 100%;height: 100%;display: flex;} </style> // 公共樣式 /* 展開字體樣式 */ .arrow-content {@apply text-base w-4 my-0 mx-auto pt-24 }/* 底部分頁footer 樣式 */.bottom-footer {@apply w-full flex items-center justify-between }

總結(jié)

以上是生活随笔為你收集整理的左右滑动栏的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。