本文实例讲述了JS实现模拟风力的雪花飘落效果。分享给大家供大家参考。具体实现方法如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>雪花飘啊飘</title> </head> <style> * {margin:0; padding:0; vertical-align:top;} .xue{position:absolute;color:#fff;} </style> <body> <div id="bbb" style="position:absolute;top:0px;right:0px;width:400px;border:1px #000 solid;background:#fff;z-index:9;height:30px;"> </div> <div id="box" style="height:600px;position:relative;border:1px red solid;background:#000;overflow:hidden;"> </div> <div style="position:absolute;top:0px;right:400px;border:1px #000 solid;background:#fff;width:400px;height:30px;z-index:5;"> <input id="wind_id" value="10" />级风 <input id="wind_button" type=button value="雪花飘啊飘飘啊飘" /> </div> <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("div"); a.innerHTML = '.'; a.id = "xue" + i; a.className = "xue"; a.style.top = parseInt(box.style.height) * (Math.random() > 0.3 "godown(\""+a+"\",\""+e+"\","+speed+")",20)} else{ clearTimeout(e); removeElement(a1); speed=null; other++; document.getElementById('bbb').innerHTML = "区域内还有"+(all-other)+"个雪花点." }; }; function wind_run(wind){ var a = document.getElementById("box").getElementsByTagName('div'); for(var i = 0;i<a.length;i++){ a[i].style.left = parseInt(a[i].style.left) + wind +'px'; }; if(Math.abs(wind) > 0.1){wind_time = setTimeout("wind_run("+wind+")",20)} else{clearTimeout(wind_time);wind = 0;}; }; gogo(); </script> </body> </html>
希望本文所述对大家的javascript程序设计有所帮助。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 纯音入心系列纯音乐《古筝系列-弦凝指咽声停处》1CD[MP3][656.5MB]
- 群星.1994-大烂片2辑【派森】【WAV+CUE】
- 吴倩莲.1997-望爱【EMI百代】【WAV+CUE】
- 杨千嬅.2002-万紫千红演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郭采洁.2015-Begin.Again爱造飞鸡【华纳】【FLAC分轨】
- 许志安.2011-ON.AND.ON【东亚】【WAV+CUE】
- 潘秀琼.1994-木兰从军【名将】【WAV+CUE】
- 纯音入心系列纯音乐《古筝系列-当流行乐遇到古筝》1CD[MP3][1.9GB]
- 纯音入心系列纯音乐《精选古筝名曲100首》1CD[MP3][388.7MB]
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】