每條游來游去的小魚,都是正在瀏覽這一頁的訪客,有一條是你自己 ( ´ ▽ ` )ノ 覺得干擾閱讀的話,可以把小魚關掉。
科幻卡片
card簡潔、實用的科幻風格資訊容器。
終於做出我夢想中的元件了!◝(≧∀≦)◟
在學階段的專業是機電與自動控制,一直對於科幻風格的元件情有獨鍾。
過去最接近的作品為:
礙於技術力不足,可以看得出來介面非常陽春,只有勉強沾上科幻的邊。(́⊙◞౪◟⊙‵)
時隔多年,總算藉由網頁技術實現我心目中的樣子了!✧⁑。٩(ˊᗜˋ*)و✧⁕。
| 名稱 | 描述 |
|---|---|
| Pointer 事件 | 偵測滑鼠或觸控點移動、點擊、懸停等等事件,取得座標、目標等等資訊 |
| Anime.js | 輕量級 JavaScript 動畫函式庫 |
| JS 動畫 | 基於 JavaScript 實現的動畫,達成更複雜、精準的動畫控制,常見套件有 GSAP、anime.js 等 |
| CSS clip-path | 以幾何路徑裁切元素的可見區域,常用於遮罩、切割與造型 |
| Vue Suspense | 處理非同步元件,提供載入中和錯誤處理 |
| Vue Provide/Inject | Vue 的依賴注入機制,允許父元件向其所有後代元件提供資料或方法 |
| Vue AsyncComponent | 非同步載入元件,可以按需載入元件,降低初始載入時間 |
| SVG | 可在 DOM 中使用的圖形格式,適合複雜圖形和動畫,配合 Vue v-bind 可以實現基於資料的動態效果 |
Title
The best things in life are actually really expensive.
<template> <div class="w-full flex flex-col gap-10 example-wrap pb-16"> <base-checkbox v-model="visible" :label="t('show')" class="example-ctrl" />
<div class="h-full flex justify-center"> <card-futuristic v-on-click-outside="() => toggleSelect(false)" :visible :selected class="font-orbitron" @click="toggleSelect(true)" > <div class="flex flex-col gap-4"> <div class="text-xl font-bold"> Title </div>
<div> The best things in life are actually really expensive. </div> </div> </card-futuristic> </div> </div></template>
<script setup lang="ts">import { vOnClickOutside } from '@vueuse/components'import { useToggle } from '@vueuse/core'import { ref } from 'vue'import { useI18n } from 'vue-i18n'import BaseCheckbox from '../../base-checkbox.vue'import CardFuturistic from '../card-futuristic.vue'
const visible = ref(true)
const [selected, toggleSelect] = useToggle(false)
const { t } = useI18n()</script>組合不同零件,產生多種的樣式。
COD-00
FUTURISTIC CARD
CARD-01
QUOTE CORNER
CARD-02
SIDE BORDER CLIP
CARD-03
SOLID BACKGROUND
ERROR
FISH OVERWEIGHT
COD
<template> <div class="w-full flex flex-col gap-4 example-wrap"> <div class="flex flex-wrap items-center justify-center gap-10"> <card-futuristic v-for="item, i in list" :key="i" v-on-click-outside="() => item.selected = false" v-bind="item" class="font-orbitron" @click="item.selected = true" > <div class="flex flex-col"> <div v-if="item.title" :class="item.titleClass" > {{ item.title }} </div>
<div v-if="item.text" :class="item.textClass" > {{ item.text }} </div> </div> </card-futuristic> </div>
<base-checkbox v-model="visible" :label="t('show')" class="checkbox sticky bottom-4 z-10 example-ctrl md:relative md:bottom-0" /> </div></template>
<script setup lang="ts">import type { Writable } from 'type-fest'import type { ExtractComponentProps } from '../../../types'import { vOnClickOutside } from '@vueuse/components'import { promiseTimeout } from '@vueuse/core'import { map, pipe } from 'remeda'import { ref, watch } from 'vue'import { useI18n } from 'vue-i18n'import BaseCheckbox from '../../base-checkbox.vue'import CardFuturistic from '../card-futuristic.vue'
type CardProp = Writable<ExtractComponentProps<typeof CardFuturistic>> & { title?: string; titleClass?: string; text?: string; textClass?: string;}
const list = ref(pipe( [ { title: 'COD-00', titleClass: 'text-xl font-bold', text: 'FUTURISTIC CARD', bg: { type: 'halftone', color: 'light-dark(#FAFAFA, #2b2b2b)', }, border: { type: 'specific', selectedColor: '#FFF', strokeWidth: 1, side: { t: {}, l: {}, b: {}, r: {}, }, }, animeSequence: { visible: { border: { duration: 400 }, }, }, }, { title: 'CARD-01', titleClass: 'text-xl font-bold', text: 'QUOTE CORNER', corner: { type: 'quote' }, content: { type: 'scale', class: 'p-4', }, bg: { type: 'halftone', color: 'light-dark(#FAFAFA, #2b2b2b)', }, border: null, animeSequence: { visible: { content: { delay: 200 }, bg: { delay: 400 }, }, }, }, { title: 'CARD-02', titleClass: 'text-xl font-bold ', text: 'SIDE BORDER CLIP', textClass: '', corner: null, content: { type: 'clip', class: 'p-4', }, bg: { type: 'typical', margin: '0', color: 'light-dark(#FAFAFA, #2b2b2b)', }, border: { type: 'side' }, animeSequence: { normal: { border: { delay: 0 }, }, visible: { border: { delay: 0 }, bg: { delay: 200 }, content: { delay: 300 }, }, hidden: { border: { delay: 300 }, bg: { delay: 0 }, content: { delay: 0 }, }, }, }, { title: 'CARD-03', titleClass: 'text-xl font-bold text-white', text: 'SOLID BACKGROUND', textClass: 'text-white', corner: null, bg: { type: 'solid', selectedColor: '#444', }, content: { type: 'typical', class: 'p-4 pl-6', }, border: { type: 'specific' }, animeSequence: { visible: { border: { delay: 400 }, }, }, }, { title: 'ERROR', titleClass: 'text-2xl font-bold text-[#ba2507] ', text: 'FISH OVERWEIGHT', textClass: 'text-[#ba2507]', corner: null, bg: { type: 'typical', margin: '4px 0px', color: 'light-dark(#ffe8e8, #451717)', }, content: { type: 'typical', class: 'py-4 px-8', }, border: { type: 'specific', color: '#ba2507', selectedColor: '#f07860', strokeWidth: 2, side: { t: {}, b: {}, }, }, animeSequence: { normal: { border: { delay: 0 }, }, visible: { border: { delay: 0 }, bg: { delay: 400 }, content: { delay: 500 }, }, hidden: { border: { delay: 300 }, bg: { delay: 0 }, content: { delay: 0 }, }, // null 表示停用動畫 selected: { content: null }, hover: { content: null }, }, }, { title: 'COD', corner: { type: 'square', size: 2, }, bg: null, content: { type: 'typical', class: 'p-1 px-2', }, border: { type: 'typical', color: '#BBB', }, animeSequence: { visible: { corner: { delay: 0 }, border: { delay: 400 }, content: { delay: 500 }, }, hidden: { corner: { delay: 400 }, border: { delay: 0 }, content: { delay: 0 }, }, }, }, ] as CardProp[], map((data) => ({ ...data, visible: false, selected: false, })),))
const visible = ref(false)watch(visible, async (value) => { for (const data of list.value) { data.visible = value await promiseTimeout(100) }})
const { t } = useI18n()</script>
<style lang="sass">.checkbox background: light-dark(#FFF, #222)</style>使用文件元件就可以產生科幻文字特效。
Futuristic Card
此元件主要由 border、bg、corner、content 與 ornament 子元件組成,由 card 父元件負責調度動畫。
子元件可以任意組合,藉此產生 N 種有趣的樣式設計。
使用 Vue 綁定 SVG 的 Attr 進行繪圖,並使用 anime.js 實現動畫
<template> <div class="w-full flex flex-col gap-4 example-wrap"> <base-checkbox v-model="visible" :label="t('show')" class="sticky top-20 z-10 example-ctrl md:relative md:top-0" />
<div class="flex flex-wrap items-center justify-center gap-20"> <card-futuristic v-for="item, i in list" :key="i" v-on-click-outside="() => item.selected = false" v-bind="item" class="font-orbitron" @click="item.selected = true" > <div class="flex flex-col gap-2"> <card-futuristic-text v-if="item.title" :text="item.title" :class="item.titleClass" class="!m-0" />
<card-futuristic-text v-for="line, j in item.textList" :key="j" :text="line" :class="item.textClass" class="!m-0" /> </div> </card-futuristic> </div> </div></template>
<script setup lang="ts">import type { Writable } from 'type-fest'import type { ExtractComponentProps } from '../../../types'import { vOnClickOutside } from '@vueuse/components'import { promiseTimeout } from '@vueuse/core'import { map, pipe } from 'remeda'import { computed, ref, watch } from 'vue'import { useI18n } from 'vue-i18n'import BaseCheckbox from '../../base-checkbox.vue'import CardFuturisticText from '../card-futuristic-text.vue'import CardFuturistic from '../card-futuristic.vue'
type CardProp = Writable<ExtractComponentProps<typeof CardFuturistic>> & { title?: string; titleClass?: string; textList?: string[]; textClass?: string;}
const { t } = useI18n()
const list = computed(() => pipe( [ { title: 'Futuristic Card', titleClass: 'text-xl font-bold', textList: [ t('textLine1'), t('textLine2'), t('textLine3'), ], bg: { type: 'halftone', color: '#0001', dotSize: '1px', size: '10px', }, corner: { type: 'quote', strokeWidth: 8, }, border: { type: 'typical', color: '#777', }, animeSequence: { visible: { corner: { delay: 0 }, bg: { delay: 400 }, border: { delay: 400 }, content: { delay: 500 }, }, hidden: { corner: { delay: 700 }, bg: { delay: 200 }, border: { delay: 100 }, content: { delay: 100 }, }, hover: { corner: null, border: null, content: null, }, selected: { corner: null, border: null, content: null, }, }, }, ] as CardProp[], map((data) => ({ ...data, visible: false, selected: false, })),))
const visible = ref(false)watch(visible, async (value) => { for (const data of list.value) { data.visible = value await promiseTimeout(100) }})</script>動態由 border、bg、corner、content 之子元件構成,由 card 父元件負責調度動畫。
子元件可以任意組合,藉此產生 N 種有趣的樣式設計。
子元件具體實作使用 Vue 綁定 SVG 的 Attr 繪圖,並用 anime.js 實現動畫
interface Props { /** 動畫序列,可自定義動畫參數 */ animeSequence?: Partial<AnimeSequence>;
visible?: boolean; selected?: boolean; /** 為空則自動處理,有提供則以參數數值為主 */ hover?: boolean;
/** null 表示不使用此元件 */ border?: BorderParam | null; bg?: BgParam | null; corner?: CornerParam | null; content?: ContentParam | null;}Methods
Section titled “Methods”interface Expose { /** 執行特定 part 狀態動畫 */ execute: (param: ExecuteParam) => Promise<void> | undefined;}interface Slots { default?: () => unknown;}