JQuery and html+css implement mouse click to set off fireworks
<span style="color: #008080"> 1</span> <span style="color: #008080"> 2</span> <span style="color: #008080"> 3</span> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <span style="color: #008080"> 4</span> <title>HTML5烟花燃放特效代码</title> <span style="color: #008080"> 5</span> <span style="color: #008080"> 6</span> <style> <span style="color: #008080"> 7 html,body{height:100%;margin:0;padding:0<span style="color: #000000">} <span style="color: #008080"> 8 ul,li{text-indent:0;text-decoration:none;margin:0;padding:0<span style="color: #000000">} <span style="color: #008080"> 9 img{border:0<span style="color: #000000">} <span style="color: #008080"> 10 body{background-color:#000;color:#999;font:100%/18px helvetica, arial, sans-serif} <span style="color: #008080"> 11 canvas{cursor:crosshair;display:block;left:0;position:absolute;top:0;z-index:20<span style="color: #000000">} <span style="color: #008080"> 12 *<span style="color: #000000">{ <span style="color: #008080"> 13 <span style="color: #000000"> margin: 0px; <span style="color: #008080"> 14 <span style="color: #000000"> padding: 0px; <span style="color: #008080"> 15 <span style="color: #000000"> } <span style="color: #008080"> 16 <span style="color: #000000"> #bg_Img{ <span style="color: #008080"> 17 <span style="color: #000000"> width: 1920px; <span style="color: #008080"> 18 <span style="color: #000000"> height: 1500px; <span style="color: #008080"> 19 <span style="color: #000000"> border: 1px solid transparent; <span style="color: #008080"> 20 background: url("start.gif"<span style="color: #000000">) repeat; <span style="color: #008080"> 21 text-<span style="color: #000000">align: center; <span style="color: #008080"> 22 <span style="color: #000000"> } <span style="color: #008080"> 23 <span style="color: #000000"> ul{ <span style="color: #008080"> 24 <span style="color: #000000"> width: 5555px; <span style="color: #008080"> 25 <span style="color: #000000"> height: 200px; <span style="color: #008080"> 26 <span style="color: #000000"> } <span style="color: #008080"> 27 <span style="color: #000000"> li{ <span style="color: #008080"> 28 font: 120px/190px "楷体"; <span style="color: #008080"> 29 <span style="color: #000000"> color: white; <span style="color: #008080"> 30 text-<span style="color: #000000">shadow: 5px 10px 10px 10px; <span style="color: #008080"> 31 list-<span style="color: #000000">style: none; <span style="color: #008080"> 32 <span style="color: #0000ff">float<span style="color: #000000">: left; <span style="color: #008080"> 33 <span style="color: #000000"> display: none; <span style="color: #008080"> 34 <span style="color: #000000"> } <span style="color: #008080"> 35 <span style="color: #000000"> #text_bd{ <span style="color: #008080"> 36 <span style="color: #000000"> width: 600px; <span style="color: #008080"> 37 <span style="color: #000000"> height: 200px; <span style="color: #008080"> 38 <span style="color: #000000"> border: 5px solid transparent; <span style="color: #008080"> 39 margin-<span style="color: #000000">left: 200px; <span style="color: #008080"> 40 <span style="color: #000000"> } <span style="color: #008080"> 41 <span style="color: #000000"> #mouse_click{ <span style="color: #008080"> 42 <span style="color: #000000"> margin: 0px auto; <span style="color: #008080"> 43 text-<span style="color: #000000">align: center; <span style="color: #008080"> 44 <span style="color: #000000"> color: white; <span style="color: #008080"> 45 <span style="color: #000000"> } <span style="color: #008080"> 46 </style> <span style="color: #008080"> 47</span> <span style="color: #008080"> 48</span> <span style="color: #008080"> 49</span> <span style="color: #008080"> 50</span> <div id="bg_Img"> <span style="color: #008080"> 51</span> <div id="text_bd"> <span style="color: #008080"> 52</span> <ul> <span style="color: #008080"> 53</span> <li>O(∩_∩)O~~</li> <span style="color: #008080"> 54</span> <li>同</li> <span style="color: #008080"> 55</span> <li>学</li> <span style="color: #008080"> 56</span> <li>们</li> <span style="color: #008080"> 57</span> <li>节</li> <span style="color: #008080"> 58</span> <li>日</li> <span style="color: #008080"> 59</span> <li>快</li> <span style="color: #008080"> 60</span> <li>乐</li> <span style="color: #008080"> 61</span> <li>~~</li> <span style="color: #008080"> 62</span> </ul> <span style="color: #008080"> 63</span> </div> <span style="color: #008080"> 64</span> <div id="mouse_click">鼠标点击释放烟花效果</div> <span style="color: #008080"> 65</span> </div> <span style="color: #008080"> 66</span> <script type="text/javascript" src="jquery-3.1.1.js"></script> <span style="color: #008080"> 67</span> <script type="text/javascript"> <span style="color: #008080"> 68 <span style="color: #0000ff">var aLi=document.querySelectorAll("li"<span style="color: #000000">); <span style="color: #008080"> 69 setInterval(a,1000<span style="color: #000000">); <span style="color: #008080"> 70 setInterval(b,2000<span style="color: #000000">); <span style="color: #008080"> 71 setInterval(c,3000<span style="color: #000000">); <span style="color: #008080"> 72 setInterval(d,4000<span style="color: #000000">); <span style="color: #008080"> 73 setInterval(e,5000<span style="color: #000000">); <span style="color: #008080"> 74 setInterval(f,6000<span style="color: #000000">); <span style="color: #008080"> 75 setInterval(g,7000<span style="color: #000000">); <span style="color: #008080"> 76 setInterval(h,8000<span style="color: #000000">); <span style="color: #008080"> 77 <span style="color: #0000ff">function<span style="color: #000000"> a() { <span style="color: #008080"> 78 aLi[0].style.display = "block" <span style="color: #008080"> 79 <span style="color: #000000"> } <span style="color: #008080"> 80 <span style="color: #0000ff">function<span style="color: #000000"> b() { <span style="color: #008080"> 81 aLi[1].style.display = "block" <span style="color: #008080"> 82 <span style="color: #000000"> } <span style="color: #008080"> 83 <span style="color: #0000ff">function<span style="color: #000000"> c() { <span style="color: #008080"> 84 aLi[2].style.display = "block" <span style="color: #008080"> 85 <span style="color: #000000"> } <span style="color: #008080"> 86 <span style="color: #0000ff">function<span style="color: #000000"> d() { <span style="color: #008080"> 87 aLi[3].style.display = "block" <span style="color: #008080"> 88 <span style="color: #000000"> } <span style="color: #008080"> 89 <span style="color: #0000ff">function<span style="color: #000000"> e() { <span style="color: #008080"> 90 aLi[4].style.display = "block" <span style="color: #008080"> 91 <span style="color: #000000"> } <span style="color: #008080"> 92 <span style="color: #0000ff">function<span style="color: #000000"> f() { <span style="color: #008080"> 93 aLi[5].style.display = "block" <span style="color: #008080"> 94 <span style="color: #000000"> } <span style="color: #008080"> 95 <span style="color: #0000ff">function<span style="color: #000000"> g() { <span style="color: #008080"> 96 aLi[6].style.display = "block" <span style="color: #008080"> 97 <span style="color: #000000"> } <span style="color: #008080"> 98 <span style="color: #0000ff">function<span style="color: #000000"> h() { <span style="color: #008080"> 99 aLi[7].style.display = "block" <span style="color: #008080">100 <span style="color: #000000"> } <span style="color: #008080">101 $(<span style="color: #0000ff">function<span style="color: #000000">(){ <span style="color: #008080">102 <span style="color: #0000ff">var Fireworks = <span style="color: #0000ff">function<span style="color: #000000">(){ <span style="color: #008080">103 <span style="color: #0000ff">var self = <span style="color: #0000ff">this<span style="color: #000000">; <span style="color: #008080">104 <span style="color: #0000ff">var rand = <span style="color: #0000ff">function(rMi, rMa){<span style="color: #0000ff">return ~~((Math.random()*(rMa-rMi+1))+<span style="color: #000000">rMi);} <span style="color: #008080">105 <span style="color: #0000ff">var hitTest = <span style="color: #0000ff">function(x1, y1, w1, h1, x2, y2, w2, h2){<span style="color: #0000ff">return !(x1 + w1 < x2 || x2 + w2 < x1 || y1 + h1 < y2 || y2 + h2 <<span style="color: #000000"> y1);}; <span style="color: #008080">106 window.requestAnimFrame=<span style="color: #0000ff">function(){<span style="color: #0000ff">return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||<span style="color: #0000ff">function(a){window.setTimeout(a,1E3/60)}}(); <span style="color: #008080">107 <span style="color: #008080">108 self.init = <span style="color: #0000ff">function<span style="color: #000000">(){ <span style="color: #008080">109 self.canvas = document.createElement('canvas'<span style="color: #000000">); <span style="color: #008080">110 self.canvas.width = self.cw =<span style="color: #000000"> $(window).innerWidth(); <span style="color: #008080">111 self.canvas.height = self.ch =<span style="color: #000000"> $(window).innerHeight(); <span style="color: #008080">112 self.particles =<span style="color: #000000"> []; <span style="color: #008080">113 self.partCount = 150<span style="color: #000000">; <span style="color: #008080">114 self.fireworks =<span style="color: #000000"> []; <span style="color: #008080">115 self.mx = self.cw/2; <span style="color: #008080">116 self.my = self.ch/2; <span style="color: #008080">117 self.currentHue = 30<span style="color: #000000">; <span style="color: #008080">118 self.partSpeed = 5<span style="color: #000000">; <span style="color: #008080">119 self.partSpeedVariance = 10<span style="color: #000000">; <span style="color: #008080">120 self.partWind = 50<span style="color: #000000">; <span style="color: #008080">121 self.partFriction = 5<span style="color: #000000">; <span style="color: #008080">122 self.partGravity = 1<span style="color: #000000">; <span style="color: #008080">123 self.hueMin = 0<span style="color: #000000">; <span style="color: #008080">124 self.hueMax = 360<span style="color: #000000">; <span style="color: #008080">125 self.fworkSpeed = 4<span style="color: #000000">; <span style="color: #008080">126 self.fworkAccel = 10<span style="color: #000000">; <span style="color: #008080">127 self.hueVariance = 30<span style="color: #000000">; <span style="color: #008080">128 self.flickerDensity = 25<span style="color: #000000">; <span style="color: #008080">129 self.showShockwave = <span style="color: #0000ff">true<span style="color: #000000">; <span style="color: #008080">130 self.showTarget = <span style="color: #0000ff">false<span style="color: #000000">; <span style="color: #008080">131 self.clearAlpha = 25<span style="color: #000000">; <span style="color: #008080">132 <span style="color: #008080">133 <span style="color: #000000"> $(document.body).append(self.canvas); <span style="color: #008080">134 self.ctx = self.canvas.getContext('2d'<span style="color: #000000">); <span style="color: #008080">135 self.ctx.lineCap = 'round'<span style="color: #000000">; <span style="color: #008080">136 self.ctx.lineJoin = 'round'<span style="color: #000000">; <span style="color: #008080">137 self.lineWidth = 1<span style="color: #000000">; <span style="color: #008080">138 <span style="color: #000000"> self.bindEvents(); <span style="color: #008080">139 <span style="color: #000000"> self.canvasLoop(); <span style="color: #008080">140 <span style="color: #008080">141 self.canvas.onselectstart = <span style="color: #0000ff">function<span style="color: #000000">() { <span style="color: #008080">142 <span style="color: #0000ff">return <span style="color: #0000ff">false<span style="color: #000000">; <span style="color: #008080">143 <span style="color: #000000"> }; <span style="color: #008080">144 <span style="color: #000000"> }; <span style="color: #008080">145 <span style="color: #008080">146 self.createParticles = <span style="color: #0000ff">function<span style="color: #000000">(x,y, hue){ <span style="color: #008080">147 <span style="color: #0000ff">var countdown =<span style="color: #000000"> self.partCount; <span style="color: #008080">148 <span style="color: #0000ff">while(countdown--<span style="color: #000000">){ <span style="color: #008080">149 <span style="color: #0000ff">var newParticle =<span style="color: #000000"> { <span style="color: #008080">150 <span style="color: #000000"> x: x, <span style="color: #008080">151 <span style="color: #000000"> y: y, <span style="color: #008080">152 <span style="color: #000000"> coordLast: [ <span style="color: #008080">153 <span style="color: #000000"> {x: x, y: y}, <span style="color: #008080">154 <span style="color: #000000"> {x: x, y: y}, <span style="color: #008080">155 <span style="color: #000000"> {x: x, y: y} <span style="color: #008080">156 <span style="color: #000000"> ], <span style="color: #008080">157 angle: rand(0, 360<span style="color: #000000">), <span style="color: #008080">158 speed: rand(((self.partSpeed - self.partSpeedVariance) <= 0) ? 1 : self.partSpeed - self.partSpeedVariance, (self.partSpeed +<span style="color: #000000"> self.partSpeedVariance)), <span style="color: #008080">159 friction: 1 - self.partFriction/100, <span style="color: #008080">160 gravity: self.partGravity/2, <span style="color: #008080">161 hue: rand(hue-self.hueVariance, hue+<span style="color: #000000">self.hueVariance), <span style="color: #008080">162 brightness: rand(50, 80<span style="color: #000000">), <span style="color: #008080">163 alpha: rand(40,100)/100, <span style="color: #008080">164 decay: rand(10, 50)/1000, <span style="color: #008080">165 wind: (rand(0, self.partWind) - (self.partWind/2))/25<span style="color: #000000">, <span style="color: #008080">166 <span style="color: #000000"> lineWidth: self.lineWidth <span style="color: #008080">167 <span style="color: #000000"> }; <span style="color: #008080">168 <span style="color: #000000"> self.particles.push(newParticle); <span style="color: #008080">169 <span style="color: #000000"> } <span style="color: #008080">170 <span style="color: #000000"> }; <span style="color: #008080">171 <span style="color: #008080">172 <span style="color: #008080">173 self.updateParticles = <span style="color: #0000ff">function<span style="color: #000000">(){ <span style="color: #008080">174 <span style="color: #0000ff">var i =<span style="color: #000000"> self.particles.length; <span style="color: #008080">175 <span style="color: #0000ff">while(i--<span style="color: #000000">){ <span style="color: #008080">176 <span style="color: #0000ff">var p =<span style="color: #000000"> self.particles[i]; <span style="color: #008080">177 <span style="color: #0000ff">var radians = p.angle * Math.PI / 180<span style="color: #000000">; <span style="color: #008080">178 <span style="color: #0000ff">var vx = Math.cos(radians) *<span style="color: #000000"> p.speed; <span style="color: #008080">179 <span style="color: #0000ff">var vy = Math.sin(radians) *<span style="color: #000000"> p.speed; <span style="color: #008080">180 p.speed *=<span style="color: #000000"> p.friction; <span style="color: #008080">181 <span style="color: #008080">182 p.coordLast[2].x = p.coordLast[1<span style="color: #000000">].x; <span style="color: #008080">183 p.coordLast[2].y = p.coordLast[1<span style="color: #000000">].y; <span style="color: #008080">184 p.coordLast[1].x = p.coordLast[0<span style="color: #000000">].x; <span style="color: #008080">185 p.coordLast[1].y = p.coordLast[0<span style="color: #000000">].y; <span style="color: #008080">186 p.coordLast[0].x =<span style="color: #000000"> p.x; <span style="color: #008080">187 p.coordLast[0].y =<span style="color: #000000"> p.y; <span style="color: #008080">188 <span style="color: #008080">189 p.x +=<span style="color: #000000"> vx; <span style="color: #008080">190 p.y +=<span style="color: #000000"> vy; <span style="color: #008080">191 p.y +=<span style="color: #000000"> p.gravity; <span style="color: #008080">192 <span style="color: #008080">193 p.angle +=<span style="color: #000000"> p.wind; <span style="color: #008080">194 p.alpha -=<span style="color: #000000"> p.decay; <span style="color: #008080">195 <span style="color: #008080">196 <span style="color: #0000ff">if(!hitTest(0,0,self.cw,self.ch,p.x-p.radius, p.y-p.radius, p.radius*2, p.radius*2) || p.alpha < .05<span style="color: #000000">){ <span style="color: #008080">197 self.particles.splice(i, 1<span style="color: #000000">); <span style="color: #008080">198 <span style="color: #000000"> } <span style="color: #008080">199 <span style="color: #000000"> }; <span style="color: #008080">200 <span style="color: #000000"> }; <span style="color: #008080">201 <span style="color: #008080">202 self.drawParticles = <span style="color: #0000ff">function<span style="color: #000000">(){ <span style="color: #008080">203 <span style="color: #0000ff">var i =<span style="color: #000000"> self.particles.length; <span style="color: #008080">204 <span style="color: #0000ff">while(i--<span style="color: #000000">){ <span style="color: #008080">205 <span style="color: #0000ff">var p =<span style="color: #000000"> self.particles[i]; <span style="color: #008080">206 <span style="color: #008080">207 <span style="color: #0000ff">var coordRand = (rand(1,3)-1<span style="color: #000000">); <span style="color: #008080">208 <span style="color: #000000"> self.ctx.beginPath(); <span style="color: #008080">209 <span style="color: #000000"> self.ctx.moveTo(Math.round(p.coordLast[coordRand].x), Math.round(p.coordLast[coordRand].y)); <span style="color: #008080">210 <span style="color: #000000"> self.ctx.lineTo(Math.round(p.x), Math.round(p.y)); <span style="color: #008080">211 <span style="color: #000000"> self.ctx.closePath(); <span style="color: #008080">212 self.ctx.strokeStyle = 'hsla('+p.hue+', 100%, '+p.brightness+'%, '+p.alpha+')'<span style="color: #000000">; <span style="color: #008080">213 <span style="color: #000000"> self.ctx.stroke(); <span style="color: #008080">214 <span style="color: #008080">215 <span style="color: #0000ff">if(self.flickerDensity > 0<span style="color: #000000">){ <span style="color: #008080">216 <span style="color: #0000ff">var inverseDensity = 50 -<span style="color: #000000"> self.flickerDensity; <span style="color: #008080">217 <span style="color: #0000ff">if(rand(0, inverseDensity) ===<span style="color: #000000"> inverseDensity){ <span style="color: #008080">218 <span style="color: #000000"> self.ctx.beginPath(); <span style="color: #008080">219 self.ctx.arc(Math.round(p.x), Math.round(p.y), rand(p.lineWidth,p.lineWidth+3)/2, 0, Math.PI*2, false) <span style="color: #008080">220 <span style="color: #000000"> self.ctx.closePath(); <span style="color: #008080">221 <span style="color: #0000ff">var randAlpha = rand(50,100)/100; <span style="color: #008080">222 self.ctx.fillStyle = 'hsla('+p.hue+', 100%, '+p.brightness+'%, '+randAlpha+')'<span style="color: #000000">; <span style="color: #008080">223 <span style="color: #000000"> self.ctx.fill(); <span style="color: #008080">224 <span style="color: #000000"> } <span style="color: #008080">225 <span style="color: #000000"> } <span style="color: #008080">226 <span style="color: #000000"> }; <span style="color: #008080">227 <span style="color: #000000"> }; <span style="color: #008080">228 <span style="color: #008080">229 <span style="color: #008080">230 self.createFireworks = <span style="color: #0000ff">function<span style="color: #000000">(startX, startY, targetX, targetY){ <span style="color: #008080">231 <span style="color: #0000ff">var newFirework =<span style="color: #000000"> { <span style="color: #008080">232 <span style="color: #000000"> x: startX, <span style="color: #008080">233 <span style="color: #000000"> y: startY, <span style="color: #008080">234 <span style="color: #000000"> startX: startX, <span style="color: #008080">235 <span style="color: #000000"> startY: startY, <span style="color: #008080">236 hitX: <span style="color: #0000ff">false<span style="color: #000000">, <span style="color: #008080">237 hitY: <span style="color: #0000ff">false<span style="color: #000000">, <span style="color: #008080">238 <span style="color: #000000"> coordLast: [ <span style="color: #008080">239 <span style="color: #000000"> {x: startX, y: startY}, <span style="color: #008080">240 <span style="color: #000000"> {x: startX, y: startY}, <span style="color: #008080">241 <span style="color: #000000"> {x: startX, y: startY} <span style="color: #008080">242 <span style="color: #000000"> ], <span style="color: #008080">243 <span style="color: #000000"> targetX: targetX, <span style="color: #008080">244 <span style="color: #000000"> targetY: targetY, <span style="color: #008080">245 <span style="color: #000000"> speed: self.fworkSpeed, <span style="color: #008080">246 angle: Math.atan2(targetY - startY, targetX -<span style="color: #000000"> startX), <span style="color: #008080">247 shockwaveAngle: Math.atan2(targetY - startY, targetX - startX)+(90*(Math.PI/180)), <span style="color: #008080">248 acceleration: self.fworkAccel/100, <span style="color: #008080">249 <span style="color: #000000"> hue: self.currentHue, <span style="color: #008080">250 brightness: rand(50, 80<span style="color: #000000">), <span style="color: #008080">251 alpha: rand(50,100)/100, <span style="color: #008080">252 <span style="color: #000000"> lineWidth: self.lineWidth <span style="color: #008080">253 <span style="color: #000000"> }; <span style="color: #008080">254 <span style="color: #000000"> self.fireworks.push(newFirework); <span style="color: #008080">255 <span style="color: #008080">256 <span style="color: #000000"> }; <span style="color: #008080">257 <span style="color: #008080">258 <span style="color: #008080">259 self.updateFireworks = <span style="color: #0000ff">function<span style="color: #000000">(){ <span style="color: #008080">260 <span style="color: #0000ff">var i =<span style="color: #000000"> self.fireworks.length; <span style="color: #008080">261 <span style="color: #008080">262 <span style="color: #0000ff">while(i--<span style="color: #000000">){ <span style="color: #008080">263 <span style="color: #0000ff">var f =<span style="color: #000000"> self.fireworks[i]; <span style="color: #008080">264 self.ctx.lineWidth =<span style="color: #000000"> f.lineWidth; <span style="color: #008080">265 <span style="color: #008080">266 vx = Math.cos(f.angle) *<span style="color: #000000"> f.speed, <span style="color: #008080">267 vy = Math.sin(f.angle) *<span style="color: #000000"> f.speed; <span style="color: #008080">268 f.speed *= 1 +<span style="color: #000000"> f.acceleration; <span style="color: #008080">269 f.coordLast[2].x = f.coordLast[1<span style="color: #000000">].x; <span style="color: #008080">270 f.coordLast[2].y = f.coordLast[1<span style="color: #000000">].y; <span style="color: #008080">271 f.coordLast[1].x = f.coordLast[0<span style="color: #000000">].x; <span style="color: #008080">272 f.coordLast[1].y = f.coordLast[0<span style="color: #000000">].y; <span style="color: #008080">273 f.coordLast[0].x =<span style="color: #000000"> f.x; <span style="color: #008080">274 f.coordLast[0].y =<span style="color: #000000"> f.y; <span style="color: #008080">275 <span style="color: #008080">276 <span style="color: #0000ff">if(f.startX >=<span style="color: #000000"> f.targetX){ <span style="color: #008080">277 <span style="color: #0000ff">if(f.x + vx <=<span style="color: #000000"> f.targetX){ <span style="color: #008080">278 f.x =<span style="color: #000000"> f.targetX; <span style="color: #008080">279 f.hitX = <span style="color: #0000ff">true<span style="color: #000000">; <span style="color: #008080">280 } <span style="color: #0000ff">else<span style="color: #000000"> { <span style="color: #008080">281 f.x +=<span style="color: #000000"> vx; <span style="color: #008080">282 <span style="color: #000000"> } <span style="color: #008080">283 } <span style="color: #0000ff">else<span style="color: #000000"> { <span style="color: #008080">284 <span style="color: #0000ff">if(f.x + vx >=<span style="color: #000000"> f.targetX){ <span style="color: #008080">285 f.x =<span style="color: #000000"> f.targetX; <span style="color: #008080">286 f.hitX = <span style="color: #0000ff">true<span style="color: #000000">; <span style="color: #008080">287 } <span style="color: #0000ff">else<span style="color: #000000"> { <span style="color: #008080">288 f.x +=<span style="color: #000000"> vx; <span style="color: #008080">289 <span style="color: #000000"> } <span style="color: #008080">290 <span style="color: #000000"> } <span style="color: #008080">291 <span style="color: #008080">292 <span style="color: #0000ff">if(f.startY >=<span style="color: #000000"> f.targetY){ <span style="color: #008080">293 <span style="color: #0000ff">if(f.y + vy <=<span style="color: #000000"> f.targetY){ <span style="color: #008080">294 f.y =<span style="color: #000000"> f.targetY; <span style="color: #008080">295 f.hitY = <span style="color: #0000ff">true<span style="color: #000000">; <span style="color: #008080">296 } <span style="color: #0000ff">else<span style="color: #000000"> { <span style="color: #008080">297 f.y +=<span style="color: #000000"> vy; <span style="color: #008080">298 <span style="color: #000000"> } <span style="color: #008080">299 } <span style="color: #0000ff">else<span style="color: #000000"> { <span style="color: #008080">300 <span style="color: #0000ff">if(f.y + vy >=<span style="color: #000000"> f.targetY){ <span style="color: #008080">301 f.y =<span style="color: #000000"> f.targetY; <span style="color: #008080">302 f.hitY = <span style="color: #0000ff">true<span style="color: #000000">; <span style="color: #008080">303 } <span style="color: #0000ff">else<span style="color: #000000"> { <span style="color: #008080">304 f.y +=<span style="color: #000000"> vy; <span style="color: #008080">305 <span style="color: #000000"> } <span style="color: #008080">306 <span style="color: #000000"> } <span style="color: #008080">307 <span style="color: #008080">308 <span style="color: #0000ff">if(f.hitX &&<span style="color: #000000"> f.hitY){ <span style="color: #008080">309 <span style="color: #000000"> self.createParticles(f.targetX, f.targetY, f.hue); <span style="color: #008080">310 self.fireworks.splice(i, 1<span style="color: #000000">); <span style="color: #008080">311 <span style="color: #008080">312 <span style="color: #000000"> } <span style="color: #008080">313 <span style="color: #000000"> }; <span style="color: #008080">314 <span style="color: #000000"> }; <span style="color: #008080">315 <span style="color: #008080">316 self.drawFireworks = <span style="color: #0000ff">function<span style="color: #000000">(){ <span style="color: #008080">317 <span style="color: #0000ff">var i =<span style="color: #000000"> self.fireworks.length; <span style="color: #008080">318 self.ctx.globalCompositeOperation = 'lighter'<span style="color: #000000">; <span style="color: #008080">319 <span style="color: #0000ff">while(i--<span style="color: #000000">){ <span style="color: #008080">320 <span style="color: #0000ff">var f =<span style="color: #000000"> self.fireworks[i]; <span style="color: #008080">321 self.ctx.lineWidth =<span style="color: #000000"> f.lineWidth; <span style="color: #008080">322 <span style="color: #008080">323 <span style="color: #0000ff">var coordRand = (rand(1,3)-1<span style="color: #000000">); <span style="color: #008080">324 <span style="color: #000000"> self.ctx.beginPath(); <span style="color: #008080">325 <span style="color: #000000"> self.ctx.moveTo(Math.round(f.coordLast[coordRand].x), Math.round(f.coordLast[coordRand].y)); <span style="color: #008080">326 <span style="color: #000000"> self.ctx.lineTo(Math.round(f.x), Math.round(f.y)); <span style="color: #008080">327 <span style="color: #000000"> self.ctx.closePath(); <span style="color: #008080">328 self.ctx.strokeStyle = 'hsla('+f.hue+', 100%, '+f.brightness+'%, '+f.alpha+')'<span style="color: #000000">; <span style="color: #008080">329 <span style="color: #000000"> self.ctx.stroke(); <span style="color: #008080">330 <span style="color: #008080">331 <span style="color: #0000ff">if<span style="color: #000000">(self.showTarget){ <span style="color: #008080">332 <span style="color: #000000"> self.ctx.save(); <span style="color: #008080">333 <span style="color: #000000"> self.ctx.beginPath(); <span style="color: #008080">334 self.ctx.arc(Math.round(f.targetX), Math.round(f.targetY), rand(1,8), 0, Math.PI*2, <span style="color: #0000ff">false<span style="color: #000000">) <span style="color: #008080">335 <span style="color: #000000"> self.ctx.closePath(); <span style="color: #008080">336 self.ctx.lineWidth = 1<span style="color: #000000">; <span style="color: #008080">337 <span style="color: #000000"> self.ctx.stroke(); <span style="color: #008080">338 <span style="color: #000000"> self.ctx.restore(); <span style="color: #008080">339 <span style="color: #000000"> } <span style="color: #008080">340 <span style="color: #008080">341 <span style="color: #0000ff">if<span style="color: #000000">(self.showShockwave){ <span style="color: #008080">342 <span style="color: #000000"> self.ctx.save(); <span style="color: #008080">343 <span style="color: #000000"> self.ctx.translate(Math.round(f.x), Math.round(f.y)); <span style="color: #008080">344 <span style="color: #000000"> self.ctx.rotate(f.shockwaveAngle); <span style="color: #008080">345 <span style="color: #000000"> self.ctx.beginPath(); <span style="color: #008080">346 self.ctx.arc(0, 0, 1*(f.speed/5), 0, Math.PI, true); <span style="color: #008080">347 self.ctx.strokeStyle = 'hsla('+f.hue+', 100%, '+f.brightness+'%, '+rand(25, 60)/100+')'; <span style="color: #008080">348 self.ctx.lineWidth =<span style="color: #000000"> f.lineWidth; <span style="color: #008080">349 <span style="color: #000000"> self.ctx.stroke(); <span style="color: #008080">350 <span style="color: #000000"> self.ctx.restore(); <span style="color: #008080">351 <span style="color: #000000"> } <span style="color: #008080">352 <span style="color: #000000"> }; <span style="color: #008080">353 <span style="color: #000000"> }; <span style="color: #008080">354 <span style="color: #008080">355 self.bindEvents = <span style="color: #0000ff">function<span style="color: #000000">(){ <span style="color: #008080">356 $(window).on('resize', <span style="color: #0000ff">function<span style="color: #000000">(){ <span style="color: #008080">357 <span style="color: #000000"> clearTimeout(self.timeout); <span style="color: #008080">358 self.timeout = setTimeout(<span style="color: #0000ff">function<span style="color: #000000">() { <span style="color: #008080">359 self.canvas.width = self.cw =<span style="color: #000000"> $(window).innerWidth(); <span style="color: #008080">360 self.canvas.height = self.ch =<span style="color: #000000"> $(window).innerHeight(); <span style="color: #008080">361 self.ctx.lineCap = 'round'<span style="color: #000000">; <span style="color: #008080">362 self.ctx.lineJoin = 'round'<span style="color: #000000">; <span style="color: #008080">363 }, 100<span style="color: #000000">); <span style="color: #008080">364 <span style="color: #000000"> }); <span style="color: #008080">365 <span style="color: #008080">366 $(self.canvas).on('mousedown', <span style="color: #0000ff">function<span style="color: #000000">(e){ <span style="color: #008080">367 self.mx = e.pageX -<span style="color: #000000"> self.canvas.offsetLeft; <span style="color: #008080">368 self.my = e.pageY -<span style="color: #000000"> self.canvas.offsetTop; <span style="color: #008080">369 self.currentHue =<span style="color: #000000"> rand(self.hueMin, self.hueMax); <span style="color: #008080">370 self.createFireworks(self.cw/2, self.ch, self.mx, self.my); <span style="color: #008080">371 <span style="color: #008080">372 $(self.canvas).on('mousemove.fireworks', <span style="color: #0000ff">function<span style="color: #000000">(e){ <span style="color: #008080">373 self.mx = e.pageX -<span style="color: #000000"> self.canvas.offsetLeft; <span style="color: #008080">374 self.my = e.pageY -<span style="color: #000000"> self.canvas.offsetTop; <span style="color: #008080">375 self.currentHue =<span style="color: #000000"> rand(self.hueMin, self.hueMax); <span style="color: #008080">376 self.createFireworks(self.cw/2, self.ch, self.mx, self.my); <span style="color: #008080">377 <span style="color: #000000"> }); <span style="color: #008080">378 <span style="color: #000000"> }); <span style="color: #008080">379 <span style="color: #008080">380 $(self.canvas).on('mouseup', <span style="color: #0000ff">function<span style="color: #000000">(e){ <span style="color: #008080">381 $(self.canvas).off('mousemove.fireworks'<span style="color: #000000">); <span style="color: #008080">382 <span style="color: #000000"> }); <span style="color: #008080">383 <span style="color: #008080">384 <span style="color: #000000"> } <span style="color: #008080">385 <span style="color: #008080">386 self.clear = <span style="color: #0000ff">function<span style="color: #000000">(){ <span style="color: #008080">387 self.particles =<span style="color: #000000"> []; <span style="color: #008080">388 self.fireworks =<span style="color: #000000"> []; <span style="color: #008080">389 self.ctx.clearRect(0, 0<span style="color: #000000">, self.cw, self.ch); <span style="color: #008080">390 <span style="color: #000000"> }; <span style="color: #008080">391 <span style="color: #008080">392 <span style="color: #008080">393 self.canvasLoop = <span style="color: #0000ff">function<span style="color: #000000">(){ <span style="color: #008080">394 <span style="color: #000000"> requestAnimFrame(self.canvasLoop, self.canvas); <span style="color: #008080">395 self.ctx.globalCompositeOperation = 'destination-out'<span style="color: #000000">; <span style="color: #008080">396 self.ctx.fillStyle = 'rgba(0,0,0,'+self.clearAlpha/100+')'; <span style="color: #008080">397 self.ctx.fillRect(0,0<span style="color: #000000">,self.cw,self.ch); <span style="color: #008080">398 <span style="color: #000000"> self.updateFireworks(); <span style="color: #008080">399 <span style="color: #000000"> self.updateParticles(); <span style="color: #008080">400 <span style="color: #000000"> self.drawFireworks(); <span style="color: #008080">401 <span style="color: #000000"> self.drawParticles(); <span style="color: #008080">402 <span style="color: #008080">403 <span style="color: #000000"> }; <span style="color: #008080">404 <span style="color: #008080">405 <span style="color: #000000"> self.init(); <span style="color: #008080">406 <span style="color: #008080">407 <span style="color: #000000"> } <span style="color: #008080">408 <span style="color: #0000ff">var fworks = <span style="color: #0000ff">new<span style="color: #000000"> Fireworks(); <span style="color: #008080">409 <span style="color: #008080">410 <span style="color: #000000"> }); <span style="color: #008080">411 <span style="color: #008080">412 </script> <span style="color: #008080">413</span> <span style="color: #008080">414</span> <span style="color: #008080">415</span>
Dear netizens! Because this was sent by the teacher during the holiday! So I can’t understand some things! I’m really sorry. If you don’t understand anything, just leave a message and tell me! I’ll go to my former teacher and ask Ask, even though he has retired for a long time!!
The above is the detailed content of JQuery and html+css implement mouse click to set off fireworks. For more information, please follow other related articles on the PHP Chinese website!

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools