OlaJavaScript 實(shí)時(shí)數(shù)據(jù)插入平滑動(dòng)畫(huà)庫(kù)
Ola 是一個(gè)簡(jiǎn)單的 JavaScript 庫(kù),實(shí)時(shí)插入/插入(inbetweening / interpolating )數(shù)字的平滑動(dòng)畫(huà)庫(kù)。
// Start tracking the value
const pos = Ola({ y: 0 });
// Set the value to update async
pos.set({ y: 100 });
// Read the evolution over time
setInterval(() => graph(pos.y), 5);
支持多值和多維度
const pos = Ola({ x: 0, y: 0 });
window.addEventListener('click', e => {
pos.set({ x: e.pageX, y: e.pageY });
});
setInterval(() => {
ball.style.left = `${pos.x}px`;
ball.style.top = `${pos.y}px`;
}, 10);
支持很多獨(dú)立的實(shí)例
// Generates 1000 instances seamlessly
const dots = Ola(Array(1000).fill(0));
// Everything updates every 600ms
setInterval(() => dots.forEach((dot, i) => {
dots[i] = Math.random();
}), 600);
// ... read + paint screen here
快速開(kāi)始
使用 npm 安裝
npm install ola
導(dǎo)入并使用
import Ola from "ola";
const pos = Ola({ x: 0 });
console.log(pos.x); // 0
可通過(guò) CDN 方式使用
<script src="https://cdn.jsdelivr.net/npm/ola"></script>
<script type="text/javascript">
const pos = Ola({ x: 0 });
console.log(pos.x); // 0
</script>評(píng)論
圖片
表情
