bug: 335 优化动画

This commit is contained in:
zdg 2024-08-30 13:35:25 +08:00
parent b249df2dff
commit 571bfc98f7
3 changed files with 65 additions and 24 deletions

View File

@ -2,6 +2,7 @@
<div class="warp" ref="btnRef" :style="isFold?'min-height:auto;':''">
<slot name="start"></slot>
<!-- 工具按钮 -->
<transition name="el-zoom-in-bottom">
<el-space direction="vertical" v-show="!isFold">
<template v-for="(item,index) in list">
<slot :name="item.prop" :item="item" :index="index">
@ -13,6 +14,7 @@
</template>
<slot name="append"></slot>
</el-space>
</transition>
<slot name="end">
<span class="fold" @click="isFold=!isFold" :style="isFold?'margin: 5px;':''">
{{isFold?'<<<':'>>>'}}

View File

@ -36,6 +36,7 @@ class Drag {
const {cx, cy} = this.getMousePos(e)
this.x = cx
this.y = cy
this.getCurPos() // 被拖拽元素初始坐标
// 手动-触发事件 v-drag-start
this.el.dispatchEvent(new CustomEvent('v-drag-start', {detail:{drag: this}}))
}
@ -85,12 +86,20 @@ class Drag {
}
// 获取移动后坐标
getPos(x, y) {
const w = this.max.w - this.toRound(this.el.clientWidth)
const h = this.max.h - this.toRound(this.el.clientHeight)
// 边界控制:图标元素
// const w = this.max.w - this.toRound(this.el.clientWidth)
// const h = this.max.h - this.toRound(this.el.clientHeight)
// 边界控制:整个工具
const w = this.max.w - this.toRound(this.handle.clientWidth)
const h = this.max.h - this.toRound(this.handle.clientHeight)
x = x < 0 ? 0 : x > w ? w : x
y = y < 0 ? 0 : y > h ? h : y
return { x, y }
}
getCurPos(dom) {
const pos = this[dom||'handle']?.getBoundingClientRect()
this.data = {left:this.toRound(pos.left), top:this.toRound(pos.top)}
}
// 小数转整数
toRound = v => Math.round(v)
}

View File

@ -20,7 +20,8 @@
<el-image :src="logo" draggable="false" />
</div>
</div>
<div class="tool-btns" v-show="!isFold">
<transition name="a-fade">
<div class="tool-btns" v-if="!isFold">
<el-segmented class="c-btns" v-model="tabActive" :options="btnList" size="large" block
@change="tabChange">
<template #default="{item}">
@ -31,6 +32,7 @@
</template>
</el-segmented>
</div>
</transition>
</div>
</div>
</template>
@ -109,6 +111,23 @@ const tabChange = (val) => {
const logoHandle = (e,t) => {
if (Date.now() - dragtime.value < 200) {
isFold.value = !isFold.value
setTimeout(() => {
// :
const dom = document.querySelector('.tool-bottom-all')
const { x } = dom.getBoundingClientRect()
const w = window.innerWidth - (470 || 80)
// if (x > w) dom.style.left = `${w}px`
if (x > w) { //
let left = x
const animatFn = () => {
left-=30
if (left < w) left == w
dom.style.left = `${left}px`
if (left > w) requestAnimationFrame(animatFn)
}
requestAnimationFrame(animatFn)
}
}, 20);
}
}
// -穿
@ -262,4 +281,15 @@ watchEffect(() => {
}
}
}
.a-fade-leave-active,.a-fade-enter-active{
transition: all .3s;
}
.a-fade-enter-from,.a-fade-leave-to{
width: 0;
opacity: 0;
}
.a-fade-enter-to,.a-fade-leave-from{
width: 350px;
opacity: 1;
}
</style>