欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS畫(huà)布動(dòng)態(tài)實(shí)現(xiàn)黑客帝國(guó)背景效果

 更新時(shí)間:2020年11月08日 08:56:06   作者:花落(→)凋謝  
這篇文章主要為大家詳細(xì)介紹了JS畫(huà)布動(dòng)態(tài)實(shí)現(xiàn)黑客帝國(guó)背景效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了JS畫(huà)布動(dòng)態(tài)實(shí)現(xiàn)黑客帝國(guó)背景效果的具體代碼,供大家參考,具體內(nèi)容如下

效果圖

完整代碼

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    *{
      padding:0;
      margin:0;
    }
    body{
      overflow: hidden;
    }
  </style>
</head>
<body>
    <canvas id="mom" style="background:#111"></canvas>
  <script>
   window.onload = function(){
    //獲取畫(huà)布對(duì)象
    var canvas = document.getElementById("mom");
    //獲取畫(huà)布的上下文
    //getContext() 方法返回一個(gè)用于在畫(huà)布上繪圖的環(huán)境。
    var context =canvas.getContext("2d");
    //獲取瀏覽器屏幕的寬度和高度
    var W = window.innerWidth;
    var H = window.innerHeight;
    //設(shè)置canvas的寬度和高度
    canvas.width = W;
    canvas.height = H;
    //每個(gè)文字的字體大小
    var fontSize = 16;
    //計(jì)算列
    var colunms = Math.floor(W /fontSize);
    //記錄每列文字的y軸坐標(biāo)
    var drops = [];
    //給每一個(gè)文字初始化一個(gè)起始點(diǎn)的位置
    //計(jì)算每一個(gè)文字所謂坐標(biāo) 存儲(chǔ)y軸的坐標(biāo) 
    for(var i=0;i<colunms;i++){
      drops.push(0);
    }
    //運(yùn)動(dòng)的文字
    var str ="JavaScript function(){}";
    //4:fillText(str,x,y);原理就是去更改y的坐標(biāo)位置
    //繪畫(huà)的函數(shù)
    function draw(){
      context.fillStyle = "rgba(0,0,0,0.05)";
      //fillRect() 方法繪制“已填色”的矩形。默認(rèn)的填充顏色是黑色。
      context.fillRect(0,0,W,H);
      //給字體設(shè)置樣式
      context.font = "700 "+fontSize+"px 微軟雅黑";
      //給字體添加顏色
      context.fillStyle ="#00cc33";//可以rgb,hsl, 標(biāo)準(zhǔn)色,十六進(jìn)制顏色
      //寫(xiě)入畫(huà)布中
      for(var i=0;i<colunms;i++){
        var index = Math.floor(Math.random() * str.length);//設(shè)置文字出發(fā)時(shí)間隨機(jī) Math.floor(Math.random()*str.length)讓數(shù)組里面的文字索引隨機(jī)出現(xiàn) 
        var x = i*fontSize;
        var y = drops[i] *fontSize;//也讓y軸方向也向下掉一個(gè)文字的距離
        context.fillText(str[index],x,y);
        // //如果要改變時(shí)間,肯定就是改變每次他的起點(diǎn)
        if(y >= canvas.height && Math.random()>0.99){
          drops[i] = 0;
        }
        drops[i]++;//讓數(shù)組里面的值每次加一,用于上面的y軸下掉 
      }
    };
    //隨機(jī)顏色
    function randColor(){
      var r = Math.floor(Math.random() * 256);
      var g = Math.floor(Math.random() * 256);
      var b = Math.floor(Math.random() * 256);
      return "rgb("+r+","+g+","+b+")";
    }
    draw();
    setInterval(draw,20);
  };
  </script>
</body>
</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論