分享JS四種好玩的黑客背景效果代碼
示例一?
<html> <head> <title>The Matrix</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> <meta charset="utf-8"> <script> /* ① 用setInterval(draw, 33)設(shè)定刷新間隔 ② 用String.fromCharCode(1e2+Math.random()*33)隨機生成字母 ③ 用ctx.fillStyle='rgba(0,0,0,.05)'; ctx.fillRect(0,0,width,height); ctx.fillStyle='#0F0′; 反復生成opacity為0.5的半透明黑色背景 ④ 用x = (index * 10)+10;和yPositions[index] = y + 10;順序確定顯示字母的位置 ⑤ 用fillText(text, x, y); 在指定位置顯示一個字母 以上步驟循環(huán)進行,就會產(chǎn)生《黑客帝國》的片頭效果。 */ $(document).ready(function () { var s = window.screen; var width = q.width = s.width; var height = q.height; var yPositions = Array(300).join(0).split(''); var ctx = q.getContext('2d'); var draw = function () { ctx.fillStyle = 'rgba(0,0,0,.05)'; ctx.fillRect(0, 0, width, height); ctx.fillStyle = 'red'; ctx.font = '10pt Georgia'; yPositions.map(function (y, index) { text = String.fromCharCode(1e2 + Math.random() * 33); x = (index * 10) + 10; q.getContext('2d').fillText(text, x, y); if (y > Math.random() * 1e4) { yPositions[index] = 0; } else { yPositions[index] = y + 10; } }); }; RunMatrix(); function RunMatrix() { Game_Interval = setInterval(draw, 30); } }); </script> </head> <body> <div align="center"> <canvas id="q" width="500" height="500"></canvas> </div> </body> </html>
示例二
<html> <head> <title>Do You Know HACKER-2</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> </head> <body> <div align="center"> <canvas id="myCanvas" width="1024" height="800" style="border:1px solid #c3c3c3;"> Your browser does not support the HTML5 canvas tag. </canvas> <script type="text/javascript"> var YPositions = Array(51).join(0).split(''); /* join() 方法用于把數(shù)組中的所有元素放入一個字符串 split() 方法用于把一個字符串分割成字符串數(shù)組 */ var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); var draw = function () { ctx.fillStyle = 'rgba(0,0,0,.05)'; ctx.fillRect(0, 0, 1024, 800); ctx.fillStyle = "#0f0"; YPositions.map(function (y, index) { /* map() 把每個元素通過函數(shù)傳遞到當前匹配集合中,生成包含返回值的新的 jQuery 對象 */ x = (index * 10); ctx.fillText(parseInt(Math.random() * 10), x, y); /* 在(x,y)坐標位產(chǎn)生一個'a'字符 index為Ypositions的下標 */ if (y > 500) { YPositions[index] = 0; } else { YPositions[index] = y + 10; } /* 如果新產(chǎn)生的字符已經(jīng)到了<canvas>的辯解 那么就使產(chǎn)生下一個新字符的位置回歸到原點 */ }); }; setInterval(draw, 30); </script> </body> </html>
示例三
<html> <head> <title>Do You Know HACKER-1</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> </head> <body> <div align="center"> <canvas id="myCanvasMatrix" width="500" height="200" style="border:1px solid #c3c3c3;"> <!-- <canvas>標簽在IE9以下的瀏覽器中并不被支持 --> Please Upgrade your browser </canvas> <br> <button type="button" id="puse">puse</button> <button type="button" id="run">run</button> </div> <script type="text/javascript"> $(document).ready(function() { /* var c2 = document.getElementById("myCanvasMatrix"); var ctx2 = c2.getContext("2d"); 其中 'ctx2' 就等同于下面的 'ctx1' */ var ctx1 = $("#myCanvasMatrix").get(0).getContext("2d"); /* 其中$("").get(0)表示獲取內(nèi)部的DOM對象引用 也就是:獲取到對象的dom對象后就可以使用對應的dom API */ /* getContext() 方法返回一個用于在畫布上繪圖的環(huán)境。 Canvas.getContext(contextID); 其中contextID參數(shù)當前唯一的合法值為'2d',也就是支持了二維繪圖 未來可能會支持'3d'這個參數(shù)哦~ */ var Matrix=function(){ /* var my_gradient=ctx1.createLinearGradient(0,0,0,170); my_gradient.addColorStop(0,"black"); my_gradient.addColorStop(1,"white"); ctx1.fillStyle=my_gradient; */ ctx1.fillStyle = 'rgba(0,0,0,.07)'; /* fillStyle 屬性設(shè)置或返回用于填充繪畫的顏色、漸變或模式。 rgba(R,G,B,A) 其中'.05'代表阿爾法透明度 */ ctx1.fillRect(0,0,500,500); /* fillRect() 方法使用 fillStyle 屬性所指定的顏色、漸變和模式來填充指定的矩形 */ ctx1.fillStyle = "#0f0"; ctx1.fillText('zhengbin', Math.random()*(500), Math.random()*(500)); ctx1.fillText('cnblogs', Math.random()*(500), Math.random()*(500)); /* 其原理就是不停的產(chǎn)生新的有透明度的背景和要顯示的內(nèi)容, 這樣新的背景不停的覆蓋舊的顯示內(nèi)容 新的內(nèi)容就突顯了出來 */ }; runFun(); var id; function stopFun(){ clearInterval(id); } function runFun(){ id = setInterval(Matrix,50); /* setInterval() 定義和用法: setInterval() 方法可按照指定的周期(以毫秒計)來調(diào)用函數(shù)或計算表達式。 setInterval() 方法會不停地調(diào)用函數(shù),直到 clearInterval() 被調(diào)用或窗口被關(guān)閉。由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的參數(shù)。 */ } $("button#puse").click(function() { stopFun(); }); $("button#run").click(function() { runFun(); }); }); </script> </body> </html>
示例四
?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> </head> <body> <canvas id="content" width="1250px" height="602px"></canvas> </body> </html> <script> var cav = document.getElementById('content'); var w = window.screen.width; var h = window.screen.height; var yPositions = Array(300).join(0).split(''); var ctx = cav.getContext('2d'); var draw = function(){ ctx.fillStyle = 'rgba(0,0,0,.05)'; ctx.fillRect(0,0,w,h); ctx.fillStyle = 'green'; ctx.font = '20px'; yPositions.map(function(y,index){ text = String.fromCharCode(1e2+Math.random()*330); x = index*10; cav.getContext('2d').fillText(text,x,y); if(y>Math.random()*1e4){ yPositions[index]=0; }else{ yPositions[index]=y+10; } }); } setInterval('draw()',30); </script>
參考文章
https://www.cnblogs.com/fenger-VIP/p/7651562.html
到此這篇關(guān)于分享四種好玩的黑客背景效果JS代碼的文章就介紹到這了,更多相關(guān)黑客背景效果 JS代碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JS關(guān)閉窗口與JS關(guān)閉頁面的幾種方法小結(jié)
本篇文章要是對JS關(guān)閉窗口與JS關(guān)閉頁面的幾種方法進行了總結(jié)介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12JavaScript之Map和Set_動力節(jié)點Java學院整理
這篇文章主要為大家詳細介紹了JavaScript之Map和Set的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06微信小程序 bindtap 事件多參數(shù)傳遞的代碼示例
在微信小程序中,我們無法直接通過 bindtap="handleClick(1,2,3)" 的方式傳遞參數(shù),而是通過自定義屬性data- 的方式傳遞,并在事件回調(diào)函數(shù)中通過event.currentTarget.dataset獲取這些參數(shù),本文給大家介紹小程序 bindtap 事件多參數(shù)傳遞的實例代碼,感興趣的朋友一起看看吧2023-12-12利用AJAX實現(xiàn)WordPress中的文章列表及評論的分頁功能
在文中列表頁方面利用AJAX制作滾動到底觸發(fā)翻頁的效果比較常見,而在評論加載時AJAX顯示正在加載也很常用,下面就來看一下如何利用AJAX實現(xiàn)WordPress中的文章列表及評論的分頁功能2016-05-05SwfUpload在IE10上不出現(xiàn)上傳按鈕的解決方法
在測試中發(fā)現(xiàn)使用了SwfUpload實現(xiàn)的無刷新上傳功能,在IE10上竟然無法使用了,難道SwfUpload不支持嗎?下面與大家分享下通過修改SwfUplad.JS文件讓其支持ie102013-06-06