生活随笔
收集整理的這篇文章主要介紹了
左右滑动栏
小編覺得挺不錯(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: {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: {setDragItemFlex() {const dragBox = this.$refs.dragBoxconst childsLen = dragBox.children.lengthfor (let i = 0; i < childsLen; i++) {const node = dragBox.children[i]if (!node.style.width) {node.style.flex = 1}}},dragControllerDiv() {const resize = document.getElementsByClassName('resize') for (let i = 0; i < resize.length; i++) {resize[i].addEventListener('mousedown', this.onMouseDown)}},onMouseDown(e) {this.resizeBox = e.targetthis.currentBox = this.resizeBox.parentNode.parentNodethis.rightBox = this.getNextElement(this.currentBox)if (!this.rightBox) {return}this.curLen = this.currentBox.clientWidththis.otherBoxWidth = this.$refs.dragBox.clientWidth - this.currentBox.clientWidth - this.rightBox.clientWidth this.startX = e.clientXdocument.addEventListener('mousemove', this.onMousemove)document.addEventListener('mouseup', this.onMouseup)},getNextElement(element) {if (element.nextElementSibling) {return element.nextElementSibling} else {let next = element.nextSiblingwhile (next && next.nodeType !== 1) { next = next.nextSibling}return next}},onMousemove(e) {const endX = e.clientXconst moveLen = endX - this.startX const CurBoxLen = this.curLen + moveLen const rightBoxLen = this.$refs.dragBox.clientWidth - CurBoxLen - this.otherBoxWidth if (CurBoxLen <= 100 || rightBoxLen <= 100) {return}this.currentBox.style.width = CurBoxLen + 'px'this.resizeBox.style.left = CurBoxLen this.rightBox.style.width = rightBoxLen + 'px'},onMouseup() {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
}.bottom-footer {@apply w-full flex items-center justify-between
}
總結(jié)
以上是生活随笔為你收集整理的左右滑动栏的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。