Every little fish swimming around is a visitor on this page right now, and one of them is you ( ´ ▽ ` )ノ If they get in the way of reading, feel free to turn them off.
Agile Button
buttonAn extremely agile button ◝( •ω• )◟
Inspired by the Doro meme collaboration from Stellar Blade — the first time I saw it, I couldn't stop laughing. (´,,•ω•,,)
Tech Keywords
Section titled “Tech Keywords”| Name | Description |
|---|---|
| Pointer Events | Detects pointer movement, clicks, hovers, and more, providing coordinates and target information |
| JS Animation | JavaScript-driven animation for more complex, precise control; popular libraries include GSAP and anime.js |
Usage Examples
Section titled “Usage Examples”Basic Usage
Section titled “Basic Usage”When disabled, triggering the button makes it dodge at ultra-high speed. ─=≡Σ((( つ•̀ω•́)つ
<template> <div class="w-full flex flex-col gap-4 example-wrap"> <div class="example-ctrl flex flex-col gap-4"> <base-checkbox v-model="disabled" :label="t('disableButton')" /> </div>
<div class="flex justify-center"> <btn-agile :label="t('clickMe')" :disabled="disabled" /> </div> </div></template>
<script setup lang="ts">import { ref } from 'vue'import { useI18n } from 'vue-i18n'import BaseCheckbox from '../../base-checkbox.vue'import BtnAgile from '../btn-agile.vue'
const { t } = useI18n()
const disabled = ref(true)</script>Form Example
Section titled “Form Example”Can't click it until you fill out the form! (╯•̀ὤ•́)╯
<template> <div class="relative w-full flex justify-center example-wrap py-24"> <div class="max-w-[20rem] flex flex-col gap-4"> <base-input v-model="form.username" :label="t('帳號 *')" class="w-full" />
<base-input v-model="form.password" type="password" :label="t('密碼 *')" class="w-full" />
<div class="mt-3 flex justify-center"> <btn-agile :label="t('登入')" :disabled z-index="30" @click="handleSubmit" /> </div> </div>
<transition name="opacity"> <div v-if="isSubmitted" class="absolute inset-0 z-[40] flex flex-col items-center justify-center gap-6 rounded-xl bg-slate-600 bg-opacity-90 text-white" @click="reset" > <span class="text-xl tracking-wide"> {{ t('表單已送出!(*´∀`)~♥') }} </span>
<span class="cursor-pointer text-xs"> {{ t('點一下再來一次') }} </span> </div> </transition> </div></template>
<script setup lang="ts">import { computed, ref } from 'vue'import { useI18n } from 'vue-i18n'import BaseInput from '../../base-input.vue'import BtnAgile from '../btn-agile.vue'
const { t } = useI18n()
const form = ref({ username: '', password: '',})const disabled = computed(() => { return form.value.username === '' || form.value.password === ''})
const isSubmitted = ref(false)function handleSubmit() { if (disabled.value) { return } isSubmitted.value = true}
function reset() { isSubmitted.value = false
form.value = { username: '', password: '', }}</script>
<style lang="sass" scoped>.opacity-enter-active, .opacity-leave-active transition-duration: 0.4s.opacity-enter-from, .opacity-leave-to opacity: 0 !important</style>How It Works
Section titled “How It Works”This time we use the trendy Motion library to implement the button animation. ( •̀ ω •́ )✧
Motion leverages hardware acceleration whenever possible, and the Vue version deeply integrates with the reactivity system, delivering excellent performance. It also comes with many useful built-in components.
Highly recommended reading: The Web Animation Performance Tier List
It provides a detailed introduction to the performance characteristics of various animation techniques and Web animation knowledge — quite interesting.
Source Code
Section titled “Source Code”interface Props { /** 按鈕內文字 */ label?: string; /** 是否停用 */ disabled?: boolean; /** 同 CSS z-index */ zIndex?: number | string; /** 同 html tabindex */ tabindex?: number | string;}const emit = defineEmits<{ (e: 'click'): void;}>()Methods
Section titled “Methods”interface Expose { }defineSlots<{ /** 按鈕 */ default?: () => unknown;}>()If you have any suggestions or questions, feel free to email me( ´ ▽ ` )ノ
If you like cool components, feel free to " Buy me a cup of coffee " to show your support!