键盘控制的烟花效果

来源:https://www.sucaihuo.com/js/2617.html 2017-08-01 23:58浏览(692) 收藏

一款键盘控制的烟花效果,可以通过键盘来控制烟花的发射位置和发射个数等等,整体的城市效果还是挺不错的,喜欢的童鞋请收下吧。
键盘控制的烟花效果
分类:html/css > 图形 难易:初级
查看演示 下载资源: 8

手机扫码访问:

下载资源 下载积分: 20 积分

页面的head部分,仅需引入一个CSS样式文件即可,代码如下:

<link type="text/css" rel="stylesheet" href="css/style.css">

页面的body部分,虽然代码较多,但不难看出用了canvas和svg来绘制整个图形,代码如下:

<div class="gradient"></div>
<div class="scene-wrapper">
	<canvas></canvas>
	<?xml version="1.0" encoding="utf-8"?>
    <!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
	<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 494.5 559.4" style="enable-background:new 0 0 494.5 559.4;" xml:space="preserve">
			<!--省略部分代码-->
			<g id="city-hall">
				<rect x="316.3" y="351.4" class="st7" width="22.3" height="27.2"/>
				<rect x="334.6" y="323.6" class="st7" width="29" height="55"/>
				<rect x="290.3" y="329.6" class="st7" width="28" height="48.9"/>
				<rect x="290.3" y="329.6" class="st8" width="11.4" height="48.9"/>
				<rect x="352.3" y="323.6" class="st8" width="11.4" height="55"/>
				<line class="st18" x1="294.1" y1="333.1" x2="294.1" y2="378.1"/>
				<line class="st18" x1="298.1" y1="333.1" x2="298.1" y2="378.1"/>
				<line class="st18" x1="356.1" y1="327.4" x2="356.1" y2="378"/>
				<line class="st18" x1="360.1" y1="327.4" x2="360.1" y2="378"/>
				<g id="windows_right_1_">
					<rect x="347.6" y="338.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="326.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="326.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="326.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="326.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="329.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="329.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="329.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="329.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="332.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="332.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="332.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="332.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="335.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="335.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="335.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="335.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="338.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="338.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="338.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="353.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="341.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="341.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="341.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="341.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="344.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="344.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="344.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="344.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="347.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="347.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="347.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="347.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="350.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="350.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="350.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="350.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="353.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="353.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="353.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="368.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="356.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="356.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="356.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="356.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="359.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="359.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="359.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="359.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="362.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="362.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="362.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="362.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="365.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="365.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="365.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="365.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="368.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="368.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="371.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="371.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="371.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="371.6" class="st10" width="1.5" height="1.5"/>
					<rect x="341.4" y="374.6" class="st10" width="1.5" height="1.5"/>
					<rect x="338.2" y="374.6" class="st10" width="1.5" height="1.5"/>
					<rect x="344.5" y="374.6" class="st10" width="1.5" height="1.5"/>
					<rect x="347.6" y="374.6" class="st10" width="1.5" height="1.5"/>
				</g>
				<g id="windows_left">
					<rect x="314.3" y="338.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="332.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="332.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="332.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="332.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="335.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="335.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="335.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="335.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="338.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="338.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="338.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="353.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="341.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="341.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="341.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="341.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="344.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="344.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="344.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="344.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="347.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="347.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="347.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="347.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="350.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="350.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="350.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="350.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="353.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="353.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="353.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="368.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="356.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="356.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="356.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="356.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="359.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="359.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="359.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="359.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="362.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="362.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="362.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="362.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="365.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="365.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="365.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="365.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="368.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="368.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="371.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="371.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="371.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="371.6" class="st10" width="1.5" height="1.5"/>
					<rect x="308" y="374.6" class="st10" width="1.5" height="1.5"/>
					<rect x="304.9" y="374.6" class="st10" width="1.5" height="1.5"/>
					<rect x="311.1" y="374.6" class="st10" width="1.5" height="1.5"/>
					<rect x="314.3" y="374.6" class="st10" width="1.5" height="1.5"/>
				</g>
				<polygon class="st19" points="313.1,378.6 313.1,372.4 340.2,372.4 340.2,378.6 		"/>
				<polygon class="st20" points="343.4,369.4 340.2,374.2 313.1,374.2 310,369.4 		"/>
				<path class="st21" d="M342.9,369.5c0.4,0,0.4-0.2,0.1-0.4c-1.8-1.1-7.7-4.1-16.2-4.1c-10.3,0-16.8,4.5-16.8,4.5H342.9z"/>
			</g>
			<line id="city-line" class="st9" x1="0" y1="378.6" x2="494.5" y2="378.6"/>
		</g>
		<g id="clouds">
			<path id="cloud-2" class="st22" d="M135.1,235.1c0,0-0.6-5.7-7.4-5.7s-7.7,6.4-7.7,6.4s-0.9-0.4-2.5-0.4c-1.6,0.1-6.4,2-5.7,7
				c0,0-3.7,1-3.7,3.8c0,2.9,3.1,3.3,3.1,3.3h48.9c0,0,1.6-0.3,1.6-2.5s-3-2.3-3-2.3l-5,0.1c0,0-0.1-6.1-7-6.1c0,0-3.1,0.1-3.8,1.3
				c0,0,1-4.8-5.3-4.8c0,0-2-0.1-2.8,0.8C135,236.1,135.3,236,135.1,235.1z"/>
			<path id="cloud-1" class="st22" d="M359.3,261c0,0-1.1-0.8-3-0.8s-4.1,1.4-4.1,2.8c0,0-1.1-0.6-3.4-0.6s-5.2,2.5-5.2,4.9h-6.2
				c0,0-2.5,0.4-2.5,2.5s0.6,2.8,2.4,2.8s36,0,36,0s4.2-0.8,4.2-5.5s-5.2-5.5-5.2-5.5s-1.4-5-6.6-5S359.3,261,359.3,261z"/>
		</g>
		<g id="triggers">
			<circle id="trigger-middle-left" class="st23" cx="229.6" cy="142.3" r="0.8"/>
			<circle id="trigger-middle-right" class="st23" cx="265.9" cy="142.3" r="0.8"/>
			<circle id="trigger-top-right" class="st23" cx="261.3" cy="135" r="0.8"/>
			<circle id="trigger-hat-right" class="st23" cx="254.3" cy="80.2" r="0.8"/>
			<circle id="trigger-hat-left" class="st23" cx="241.1" cy="80.2" r="0.8"/>
			<circle id="trigger-top-left" class="st23" cx="234" cy="135" r="0.8"/>
			<circle id="trigger-bottom-left" class="st23" cx="230.7" cy="149.1" r="0.8"/>
			<circle id="trigger-bottom-right" class="st23" cx="264.7" cy="149.1" r="0.8"/>
		</g>
	</svg>
	<div class="instructions">按键 <span>A</span>, <span>S</span>, <span>D</span>, <span>F</span> 可控制焰火。</div>
</div>

页面的底部,需远程调用多个JS文件,并引入一个本地JS文件,代码如下:

<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/plugins/CSSPlugin.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TimelineLite.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenMax.min.js'></script>
<script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/49240/vector2D.js'></script>
<script type="text/javascript" src="js/index.js"></script>
评论2
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 3007547952

  • 头像 椅子
    08-22 16:30
    c***6
    so cool-------------------------
  • 头像 沙发
    08-02 11:04
    慢***a
    看起来好cool
1 2