fix: btn animate

This commit is contained in:
Zephyruso 2023-09-02 22:33:41 +08:00
parent 5d43ea0b5f
commit a29e638c1e
4 changed files with 19 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import ProxyCardGroups from '~/components/ProxyCardGroups'
import ProxyNodePreview from '~/components/ProxyNodePreview'
import { useProxies } from '~/signals/proxies'
import type { Proxy } from '~/types'
import { getBtnElFromClickEvent } from '~/utils/proxies'
export default () => {
const [t] = useI18n()
@ -22,7 +23,7 @@ export default () => {
}
const onSpeedTestClick = async (e: MouseEvent, name: string) => {
const el = e.target as HTMLElement
const el = getBtnElFromClickEvent(e)
el.classList.add('animate-pulse')
e.stopPropagation()

View File

@ -7,7 +7,7 @@ import ProxyCardGroups from '~/components/ProxyCardGroups'
import ProxyNodePreview from '~/components/ProxyNodePreview'
import SubscriptionInfo from '~/components/SubscriptionInfo'
import { useProxies } from '~/signals/proxies'
import { formatTimeFromNow } from '~/utils/proxies'
import { formatTimeFromNow, getBtnElFromClickEvent } from '~/utils/proxies'
export default () => {
const [t] = useI18n()
@ -23,7 +23,7 @@ export default () => {
)
const onHealthCheckClick = async (e: MouseEvent, name: string) => {
const el = e.target as HTMLElement
const el = getBtnElFromClickEvent(e)
el.classList.add('animate-pulse')
e.stopPropagation()
@ -32,7 +32,7 @@ export default () => {
}
const onUpdateProviderClick = async (e: MouseEvent, name: string) => {
const el = e.target as HTMLElement
const el = getBtnElFromClickEvent(e)
el.classList.add('animate-spin')
e.stopPropagation()
@ -41,7 +41,7 @@ export default () => {
}
const onUpdateAllProviderClick = async (e: MouseEvent) => {
const el = e.target as HTMLElement
const el = getBtnElFromClickEvent(e)
el.classList.add('animate-spin')
e.stopPropagation()

View File

@ -3,7 +3,7 @@ import { IconReload } from '@tabler/icons-solidjs'
import InfiniteScroll from 'solid-infinite-scroll'
import { For, Show, createMemo, createSignal, onMount } from 'solid-js'
import { useRules } from '~/signals/rules'
import { formatTimeFromNow } from '~/utils/proxies'
import { formatTimeFromNow, getBtnElFromClickEvent } from '~/utils/proxies'
export default () => {
const [t] = useI18n()
@ -22,7 +22,7 @@ export default () => {
})
const onUpdateProviderClick = async (e: MouseEvent, name: string) => {
const el = e.target as HTMLElement
const el = getBtnElFromClickEvent(e)
el.classList.add('animate-spin')
e.stopPropagation()
@ -31,7 +31,7 @@ export default () => {
}
const onUpdateAllProviderClick = async (e: MouseEvent) => {
const el = e.target as HTMLElement
const el = getBtnElFromClickEvent(e)
el.classList.add('animate-spin')
e.stopPropagation()

View File

@ -6,3 +6,13 @@ dayjs.extend(relativeTime)
export function formatTimeFromNow(time: number | string) {
return dayjs(time).fromNow()
}
export function getBtnElFromClickEvent(event: MouseEvent) {
let el = event.target as HTMLElement
while (el && !el.classList.contains('btn')) {
el = el.parentElement!
}
return el
}