Skip to content

Commit

Permalink
fix: drag sideBtn trigger click event
Browse files Browse the repository at this point in the history
  • Loading branch information
festoney8 committed Oct 5, 2024
1 parent e8c612c commit 325d568
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/views/SideBtnView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<div
ref="target"
class="mt-1 flex h-10 w-10 cursor-pointer items-center justify-center rounded-lg border border-gray-200 bg-white transition-colors hover:border-none hover:bg-[#00AEEC] hover:text-white"
@click="ruleStore.isShow ? ruleStore.hide() : ruleStore.show()"
@click="!isDragging && (ruleStore.isShow ? ruleStore.hide() : ruleStore.show())"
>
<div>
<p class="select-none text-center text-[13px] leading-4">页面</p>
Expand Down Expand Up @@ -86,17 +86,25 @@ const { width, height } = useElementBounding(target, { windowScroll: false })
const btnPos = useStorage('bili-cleaner-side-btn-pos', { right: 6, bottom: 165 }, localStorage)
const isDragging = ref(false)
useDraggable(target, {
initialValue: {
x: document.documentElement.clientWidth - btnPos.value.right,
y: document.documentElement.clientHeight - btnPos.value.bottom,
},
preventDefault: true,
handle: computed(() => target.value),
onMove: (position: Position) => {
isDragging.value = true
btnPos.value.right = document.documentElement.clientWidth - position.x - width.value
btnPos.value.bottom = document.documentElement.clientHeight - position.y - height.value
},
handle: computed(() => target.value),
onEnd: () => {
setTimeout(() => {
isDragging.value = false
}, 100)
},
})
// 限制拖拽范围
Expand Down

0 comments on commit 325d568

Please sign in to comment.