This article mainly introduces how JS can simulate the falling snow of wind power. You can enter the wind power value on the right side and click the button to see the falling snow with wind power. At the same time, the real-time statistics function is available on the right side, if you need it, you can refer to the examples in this article to describe how javascript can simulate the falling snow of wind power. Share it with you for your reference. The specific implementation method is as follows:
Snow float and floatLevel
Script var box = document. getElementById ("box"); var I = 0, c, d, wind_time; var all = 0, other = 0, wind = 0; box. style. width = '1000px '; document. getElementById ("wind_button "). onclick = function () {clearTimeout (wind_time); wind = 0; wind = parseInt (document. getElementById ("wind_id "). value); wind_run (wind);} function gogo () {var a = document. createElement ("p");. innerHTML = '. ';. id = "xue" + I;. className = "xue"; A. style. top = parseInt (box. style. height) * (Math. random ()> 0.3? Math. random (): 0) + 'px '; if (wind! = 0) {var ss = Math. random ()> Math. abs (wind * 0.025 )? Math. random (): (wind> 0? 0: 1);} else {var ss = Math. random ()}. style. left = parseInt (box. style. width) * ss + 'px '; box. appendChild (a); godown (. id,. id, 8 * Math. random (); I ++; all ++; var x = 100 * Math. random () * Math. random (); setTimeout ('gogo () ', x) ;}; function removeElement (_ element) {// function var _ parentElement = _ element to remove tags. parentNode; if (_ parentElement) {_ parentElement. removeChild (_ element) ;};}; function godown (a, e, speed) {if (speed <3) {speed = 3} var a1 = document. getElementById (a); a1.style. top = parseInt (a1.style. top) + speed + 'px '; if (parseInt (a1.style. top) <parseInt (box. style. height) {e = setTimeout ("godown (\" "+ a +" \ ", \" "+ e +" \ "," + speed + ")", 20)} else {clearTimeout (e); removeElement (a1); speed = null; other ++; document. getElementById ('bbb '). innerHTML = "there are" + (all-other) + "Snowflake points in the area. "};}; function wind_run (wind) {var a = document. getElementById ("box "). getElementsByTagName ('P'); for (var I = 0; I 0.1) {wind_time = setTimeout ("wind_run (" + wind + ")", 20 )} else {clearTimeout (wind_time); wind = 0 ;};}; gogo (); script
I hope this article will help you design javascript programs.