“還在為 Vue 動畫卡頓掉幀煩惱?只需 3 行程式碼,讓你的元素切換絲滑到飛起!🚀”
今天給大家安利一個我最近發現的寶藏 Vue 元件——vue-flip-motion
!它基於 FLIP 動畫技術(First Last Invert Play),能輕鬆實現高性能、無卡頓的過渡效果,無論是列表重排、元素縮放還是顏色漸變,統統搞定!
mutation
就能觸發效果!
(GIF 展示:點擊按鈕瞬間觸發的絲滑高度/顏色變化)
安裝:
npm install vue-flip-motion
程式碼示例(Vue 3):
<template>
<Flip
:mutation="styles"
:styles="['backgroundColor']"
:animate-option="{ duration: 1000 }"
>
<div
class="box"
@click="handleClick"
:style="{ height: styles.height, background: styles.bgColor }"
/>
</Flip>
</template>
<script setup>
import { ref } from 'vue';
import Flip from 'vue-flip-motion';
const styles = ref({ height: '100px', bgColor: '#42b983' });
const handleClick = () => {
styles.value = { height: '200px', bgColor: '#ff0000' }; // 點我觸發動畫!
};
</script>
animateOption
支持 easing
、delay
等參數,連貝塞爾曲線都能玩!:animate-option={
duration: 800,
easing: 'cubic-bezier(0.68, -0.6, 0.32, 1.6)', // 彈跳效果
iterations: Infinity // 無限循環
}
👉 GitHub 地址:github.com/qianyuanjia…
👉 npm 地址:www.npmjs.com/package/vue…
現在就用起來,讓你的專案動畫體驗提升 200%! 🚀