每逢春節、元宵等節慶,許多地方都有放煙花的傳統。若想在網頁上重現煙花綻放的絢麗場景,過去多半得依賴 JavaScript 拼湊;而自從 HTML5 興起之後,無論是模擬的難度或畫面的逼真度,都提升到全新層次。
效果展示:
https://hovertree.com/texiao/html5/43/
效果圖:

程式碼如下:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>html5 canvas全屏煙花動畫特效 - 何問起</title><base target="_blank" />
<link rel="stylesheet" type="text/css" href="https://hovertree.com/texiao/html5/43/css/normalize.css" />
<link rel="stylesheet" type="text/css" href="https://hovertree.com/texiao/html5/43/css/hovertree.css">
</head>
<body>
<div class="hovertree"></div>
<script type="text/javascript" src="https://down.hovertree.com/jquery/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="https://hovertree.com/texiao/html5/43/js/jquery.fireworks.js"></script>
<script type="text/javascript">
$('.hovertree').fireworks({
sound: true, // sound effect
opacity: 0.9,
width: '100%',
height: '100%'
});
</script>
<div style="width:340px;position:fixed;z-index:99;">來源:<a href="https://hovertree.com/">何問起</a> <a href="https://hovertree.com/h/bjag/me34x8fk.htm">說明</a></div>
</body>
</html>HTML5 的進步不僅體現在圖像處理上,在聲音方面同樣出色。這支煙花特效甚至能讓你自由切換音效:將 sound 設為 true 便有聲光效果,設為 false 則是純視覺享受。
本特效原始碼下載:
https://hovertree.com/h/bjag/24o31rk5.htm
HTML5 相關練習題
以下哪一項不是 canvas 的方法:
A、getContext() B、fill() C、stroke() D、controller()
答案:https://hovertree.com/tiku/bjaf/4tlxjl9k.htm
相關效果:
https://hovertree.com/h/bjaf/epbhdsa3.htm