一個html5流星雨源碼

流星會隨著鼠標的方向劃過,按緊鼠標左鍵可以增長流星的尾巴。 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="zh-CN"> <head> <title>流星雨</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <meta http-equiv="content-language" content="zh-CN"> <style type="text/css"> body {margin:0;padding:0;background-color:#000000;font-size:0;overflow:hidden} div {margin:0;padding:0;position:absolute;font-size:0;overflow:hidden} canvas{background-color:#000000;overflow:hidden} </style> </head> <script type="text/javascript"> function $i(id) { return document.getElementById(id); } function $r(parent,child) { (document.getElementById(parent)).removeChild(document.getElementById(child)); } function $t(name) { return document.getElementsByTagName(name); } function $c(code) { return String.fromCharCode(code); } function $h(value) { return ('0'+Math.max(0,Math.min(255,Math.round(value))).toString(16)).slice(-2); } function _i(id,value) { $t('div')[id].innerHTML+=value; } function _h(value) { return !hires?value:Math.round(value/2); } function get_screen_size() { var w=document.documentElement.clientWidth; var h=document.documentElement.clientHeight; return Array(w,h); } var url=document.location.href; var flag=true; var test=true; var n=parseInt((url.indexOf('n=')!=-1)?url.substring(url.indexOf('n=')+2,((url.substring(url.indexOf('n=')+2,url.length)).indexOf('&')!=-1)?url.indexOf('n=')+2+(url.substring(url.indexOf('n=')+2,url.length)).indexOf('&'):url.length):512); var w=0; var h=0; var x=0; var y=0; var z=0; var star_color_ratio=0; var star_x_save,star_y_save; var star_ratio=256; var star_speed=4; var star_speed_save=0; var star=new Array(n); var color; var opacity=0.1; var cursor_x=0; var cursor_y=0; var mouse_x=0; var mouse_y=0; var canvas_x=0; var canvas_y=0; var canvas_w=0; var canvas_h=0; var context; var key; var ctrl; var timeout; var fps=0; function init() { var a=0; for(var i=0;i<n;i++) { star[i]=new Array(5); star[i][0]=Math.random()*w*2-x*2; star[i][1]=Math.random()*h*2-y*2; star[i][2]=Math.round(Math.random()*z); star[i][3]=0; star[i][4]=0; } var starfield=$i('starfield'); starfield.style.position='absolute'; starfield.width=w; starfield.height=h; context=starfield.getContext('2d'); context.fillStyle='rgb(0,0,0)'; context.strokeStyle='rgb(255,255,255)'; var adsense=$i('adsense'); adsense.style.left=Math.round((w-728)/2)+'px'; adsense.style.top=(h-15)+'px'; adsense.style.width=728+'px'; adsense.style.height=15+'px'; adsense.style.display='block'; } function anim() { mouse_x=cursor_x-x; mouse_y=cursor_y-y; context.fillRect(0,0,w,h); for(var i=0;i<n;i++) { test=true; star_x_save=star[i][3]; star_y_save=star[i][4]; star[i][0]+=mouse_x>>4; if(star[i][0]>x<<1) { star[i][0]-=w<<1; test=false; } if(star[i][0]<-x<<1) { star[i][0]+=w<<1; test=false; } star[i][1]+=mouse_y>>4; if(star[i][1]>y<<1) { star[i][1]-=h<<1; test=false; } if(star[i][1]<-y<<1) { star[i][1]+=h<<1; test=false; } star[i][2]-=star_speed; if(star[i][2]>z) { star[i][2]-=z; test=false; } if(star[i][2]<0) { star[i][2]+=z; test=false; } star[i][3]=x+(star[i][0]/star[i][2])*star_ratio; star[i][4]=y+(star[i][1]/star[i][2])*star_ratio; if(star_x_save>0&&star_x_save<w&&star_y_save>0&&star_y_save<h&&test) { context.lineWidth=(1-star_color_ratio*star[i][2])*2; context.beginPath(); context.moveTo(star_x_save,star_y_save); context.lineTo(star[i][3],star[i][4]); context.stroke(); context.closePath(); } } timeout=setTimeout('anim()',fps); } function move(evt) { evt=evt||event; cursor_x=evt.pageX-canvas_x; cursor_y=evt.pageY-canvas_y; } function key_manager(evt) { evt=evt||event; key=evt.which||evt.keyCode; switch(key) { case 27: flag=flag?false:true; if(flag) { timeout=setTimeout('anim()',fps); } else { clearTimeout(timeout); } break; case 32: star_speed_save=(star_speed!=0)?star_speed:star_speed_save; star_speed=(star_speed!=0)?0:star_speed_save; break; case 13: context.fillStyle='rgba(0,0,0,'+opacity+')'; break; } top.status='key='+((key<100)?'0':'')+((key<10)?'0':'')+key; } function release() { switch(key) { case 13: context.fillStyle='rgb(0,0,0)'; break; } } function mouse_wheel(evt) { evt=evt||event; var delta=0; if(evt.wheelDelta) { delta=evt.wheelDelta/120; } else if(evt.detail) { delta=-evt.detail/3; } star_speed+=(delta>=0)?-0.2:0.2; if(evt.preventDefault) evt.preventDefault(); } function start() { resize(); anim(); } function resize() { w=parseInt((url.indexOf('w=')!=-1)?url.substring(url.indexOf('w=')+2,((url.substring(url.indexOf('w=')+2,url.length)).indexOf('&')!=-1)?url.indexOf('w=')+2+(url.substring(url.indexOf('w=')+2,url.length)).indexOf('&'):url.length):get_screen_size()[0]); h=parseInt((url.indexOf('h=')!=-1)?url.substring(url.indexOf('h=')+2,((url.substring(url.indexOf('h=')+2,url.length)).indexOf('&')!=-1)?url.indexOf('h=')+2+(url.substring(url.indexOf('h=')+2,url.length)).indexOf('&'):url.length):get_screen_size()[1]); x=Math.round(w/2); y=Math.round(h/2); z=(w+h)/2; star_color_ratio=1/z; cursor_x=x; cursor_y=y; init(); } document.οnmοusemοve=move; document.οnkeypress=key_manager; document.οnkeyup=release; document.onmousewheel=mouse_wheel; if(window.addEventListener) window.addEventListener('DOMMouseScroll',mouse_wheel,false); </script> <body οnlοad="start()" οnresize="resize()" onorientatiοnchange="resize()" οnmοusedοwn="context.fillStyle='rgba(0,0,0,'+opacity+')'" οnmοuseup="context.fillStyle='rgb(0,0,0)'"> <canvas id="starfield" style="background-color:#000000"></canvas> <div id="adsense" style="position:absolute;background-color:transparent;display:none"> </div> </body> </html> 下面附上源碼效果流星雨

轉載于:https://www.cnblogs.com/mrjim/archive/2011/10/20/4475287.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/275242.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/275242.shtml
英文地址,請注明出處:http://en.pswp.cn/news/275242.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

csdn 用戶 螞蟻翹大象_用戶界面設計師房間里的大象

csdn 用戶 螞蟻翹大象Once upon a time, an educated eye detected a new trend in UI designs, particularly, in Dribbble. It was a conceptual proposition, not an actual design for a customer or an app. Trying to explain the characteristics of this new trend, a …

面試官問發布訂閱模式是在問什么?

大家好&#xff0c;我是若川。最近組織了源碼共讀活動&#xff0c;感興趣的可以加我微信 ruochuan12 參與&#xff0c;已進行了三個多月&#xff0c;大家一起交流學習&#xff0c;共同進步。本文來自 simonezhou 小姐姐投稿的第八期筆記。面試官常問發布訂閱、觀察者模式&#…

linux服務器內存、根目錄使用率、某進程的監控告警腳本

腳本內容如下 #!/bin/bash#磁盤超過百分之80發送郵件告警DISK_USEDdf -T |sed -n "2p" |awk {print ($4/$3)*100}DISK_percentage80if [ expr "$DISK_USED > $DISK_percentage" ]thenecho "$HOSTNAME服務器當前硬盤使用率為$DISK_USED%" | ma…

figma下載_不用擔心Figma中的間距

figma下載重點 (Top highlight)I spend way too much time caring about spacing when designing interfaces and building design systems. You are probably no stranger to the constant 1 px and 8 px nudging, continuous checking of the bottom or in-between space for…

【建議收藏】面試官賊喜歡問的 32+ vue 修飾符,你掌握幾種啦?

大家好&#xff0c;我是若川。最近組織了源碼共讀活動&#xff0c;感興趣的可以加我微信 ruochuan12 參與&#xff0c;已進行了三個多月&#xff0c;大家一起交流學習&#xff0c;共同進步。前言vue簡潔好用體現在很多個地方&#xff0c;比如其內置了32修飾符&#xff0c;可以很…

知識管理系統Data Solution研發日記之一 場景設計與需求列出

在平時開發的過程中&#xff0c;經常會查找一些資料&#xff0c;從網上下載一些網頁&#xff0c;壓縮格式文件到自己的電腦中&#xff0c;然后閱讀。程序有別于其他行業的一個特征是&#xff0c;所有的資料&#xff0c;數據&#xff0c;壓縮文件&#xff0c;只用于產生可以工作…

系列TCP/IP協議-動態IP選路協議(008)

一、引言 前一章已經說過了IP數據包是如何分發的。為啥這一章還要說這個問題&#xff1f;在網絡很小、只有單個連接點、沒有多余的路由的時候&#xff0c;使用靜態選路是可以的。但是一旦網絡變大一點就會出現各種問題。在大網絡中的網絡選路將在該節說明。 ??動態選路協議用…

shields 徽標_我們如何準確地記住著名徽標的特征和顏色?

shields 徽標The logos of global corporations like Apple, Starbucks, Adidas, and IKEA are designed to create instant brand associations in the minds of billions who see them every day. But how accurately can we remember the features and colors of these famo…

面了三次字節,他的一些感悟

大家好&#xff0c;我是若川。最近組織了源碼共讀活動&#xff0c;感興趣的可以加我微信 ruochuan12 參與&#xff0c;已進行了三個多月&#xff0c;大家一起交流學習&#xff0c;共同進步。今天分享一篇小K投稿的字節面試記錄&#xff0c;這是他第三次面字節了&#xff0c;之前…

JavaScript數組內置排序函數

javascript內置的sort函數是多種排序算法的集合 JavaScript實現多維數組、對象數組排序&#xff0c;其實用的就是原生的sort()方法&#xff0c;用于對數組的元素進行排序。 sort() 方法用于對數組的元素進行排序。語法如下&#xff1a; ArrayObject.sort(order); 測試A&#xf…

解決Wireshark安裝Npcap組件失敗

2019獨角獸企業重金招聘Python工程師標準>>> 解決Wireshark安裝Npcap組件失敗 從Wireshark 3.0開始&#xff0c;Npcap取代Winpcap組件&#xff0c;成為Wireshark默認的網卡核心驅動。由于該組件屬于驅動程序&#xff0c;所以安裝時候容易被殺毒/防火墻軟件攔截&…

adobe清理工具_Adobe終于通過其新的漸變工具實現了這一點-UX評論

adobe清理工具的Photoshop (Photoshop) UX:用戶體驗&#xff1a; At first glance, the UX looks okay; it’s pretty clear. The user gets to know how to use this tool right away. The color palette is located above, and the gradient down below. The diamond betwee…

GMF學習系列(二) 一些知識點(續2)

8.插件的國際化&#xff0c;可以參考nwpu.cdcsp.sbpel.diagram.part中messages.java的做法。 9.Text自動提示功能 import org.eclipse.jface.bindings.keys.KeyStroke; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.fieldassist.AutoCompleteField; im…

新手向:前端程序員必學基本技能——調試JS代碼

1前言大家好&#xff0c;我是若川。最近組織了源碼共讀活動&#xff0c;感興趣的可以加我微信 ruochuan12 參與&#xff0c;已進行三個月了&#xff0c;大家一起交流學習&#xff0c;共同進步。想學源碼&#xff0c;極力推薦之前我寫的《學習源碼整體架構系列》 包含jQuery、un…

iOS開發ApplePay的介紹與實現

1、Apple Pay的介紹 Apple Pay官方1.1 Apple Pay概念 Apple Pay&#xff0c;簡單來說, 就是一種移動支付方式。通過Touch ID/ Passcode&#xff0c;用戶可使用存儲在iPhone 6, 6p等之后的新設備上的信用卡和借記卡支付證書來授權支付&#xff1b; 它是蘋果公司在2014蘋果秋季新…

mes建設指南_給予和接受建設性批評的設計師指南

mes建設指南Constructive criticism, or more plainly, feedback, plays a crucial role in a designer’s job. Design is an iterative process, so we are often either asking for feedback on our own work or dishing it out to a fellow designer.建設性的批評&#xff…

面試官:請實現一個通用函數把 callback 轉成 promise

1. 前言大家好&#xff0c;我是若川。最近組織了源碼共讀活動&#xff0c;感興趣的可以加我微信 ruochuan12 參與&#xff0c;或者在公眾號&#xff1a;若川視野&#xff0c;回復"源碼"參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。已進行…

java中filter的用法

filter過濾器主要使用于前臺向后臺傳遞數據是的過濾操作。程度很簡單就不說明了&#xff0c;直接給幾個已經寫好的代碼&#xff1a; 一、使瀏覽器不緩存頁面的過濾器 Java代碼 import javax.servlet.*;import javax.servlet.http.HttpServletResponse;import java.io.IOExcept…

我很喜歡玩游戲,那么我就適合做游戲程序員嗎?

作者&#xff1a;黃小斜文章來源&#xff1a;【程序員江湖】游戲在今天的普及度已經不是端游時代可以比肩的了。如今人手一臺手機、平板就可以吃雞、打農藥&#xff0c;不僅是男生&#xff0c;也有很多女生加入了游戲圈。相信現在在看文章的你也玩游戲&#xff0c;雖然愛玩的程…

open-falcon_NASA在Falcon 9上帶回了蠕蟲-其背后的故事是什么?

open-falconYes, that’s right. The classic NASA “worm” logo is back! An image of the revived NASA worm logo was released on Twitter by NASA Administrator Jim Bridenstine as well as press release on the NASA.gov website. NASA explained that original NASA …