酷炫屏幕——HTML界面

发表在    IT女(Java部落) 07-24 17:17:45

5 2576 4

这是个动态界面


<!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>

今天看到一个挺有意思的画面,就像电影中黑客的屏幕一样。运行如下图:

he


登录或注册后发布评论