這是一款別具巧思的數字時鐘動畫:數字由許多小愛心拼湊而成,仔細看還會發現愛心在輕輕蠕動。隨著時間推進,每一秒都有新數字替換舊數字,而離場的舊數字則以「天女散花」的方式消散,花瓣五彩繽紛,視覺效果相當療癒。
查看效果:
https://hovertree.com/texiao/html5/48/
推薦其他時鐘:
https://hovertree.com/h/bjaf/o0yqj1ly.htm
https://hovertree.com/h/bjaf/hoverclock.htm
程式碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5 Canvas愛心時鐘代碼 - 何問起</title>
</head>
<body>
<canvas id="canvas"></canvas>
<script type="text/javascript" src="https://hovertree.com/texiao/html5/48/js/digit.js"></script>
<script type="text/javascript" src="https://hovertree.com/texiao/html5/48/js/app.js"></script>
<div style="text-align:center;margin-top:50px; font:normal 14px/24px 'MicroSoft YaHei';">
<h2>HTML5 Canvas愛心時鐘</h2>
<p>來源:<a href="https://hovertree.com/h/bjag/oppeym4s.htm" target="_blank">何問起</a></p>
</div>
</body>
</html>
整體架構相當輕巧:頁面只需一個 canvas 元素,再依序載入 digit.js(負責把數字拆解成一格格點陣)與 app.js(負責渲染愛心與散花動畫)即可。透過 Canvas 的即時繪製能力,讓每一秒的數字轉換都充滿生命力。