java吧 关注:1,248,485贴子:12,730,802
  • 3回复贴,共1

新人 html canvas标签求助

只看楼主收藏回复

不多说 上代码


1楼2014-04-23 11:12回复
    <!-- saved from url=(0037)http://sandbox.runjs.cn/show/szyisytb -->
    <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>test</title>
    </head>
    <body style="margin: 0px; background-color: rgb(0, 0, 0); overflow: hidden; background-position: initial initial; background-repeat: initial initial;">
    <canvas width="1364" height="1120"></canvas>
    <script type="text/javascript">
    // By: Elias Schütt
    // Twitter: @elias94xx
    // Website: http://elias-schuett.de
    var b = document.body;
    var c = document.getElementsByTagName('canvas')[0];
    var a = c.getContext('2d');
    document.body.clientWidth; // fix bug in webkit: http://qfox.nl/weblog/218
    // start of submission //
    // JS1K ヽ(*⌒∇⌒*)ノ
    S = b.innerHTML.split("\n");
    so = 0; fs = "fillStyle";
    lo = 1; ln = "length";
    c.width = W = innerWidth;
    c.height = H = S.length*20;
    b.style.margin = 0;
    b.style.background = "#000";
    b.style.overflow = "hidden";
    a.textBaseline = "top";
    a.font = "12px monospace";
    x = setInterval(function() {
    a.globalCompositeOperation = "source-over";
    a.shadowBlur = 0; a[fs] = "rgba(0,0,0,0.4)";
    a.fillRect(0,0,W,H);
    a.shadowColor = "rgba(0,255,0,0.5)";
    a.shadowBlur = 10; a[fs] = "#060";
    a.globalCompositeOperation = "lighter";
    S.forEach(function(v, i) {
    if (i <= lo) {
    if (i == lo) { v = v.substr(0, so); }
    a.fillText(v, 100, 100+i*16);
    }
    });
    a[fs] = "#0f0";
    a.fillRect(100+a.measureText(S[lo].substr(0, so)).width, 102+lo*16, 10, 14);
    so++;
    if (so >= S[lo][ln]) { lo++; so = 0; }
    if (lo*16 > innerHeight-200) { a.translate(0, -0.5); }
    if (lo >= S[ln]-1) { window.clearInterval(x); }
    }, 25);
    // end of submission //
    </script>
    <style></style>
    <script></script>
    <!-- Generated by RunJS (Wed Apr 23 11:24:35 CST 2014) 1ms --><div><object id="ClCache" click="sendMsg" host="" width="0" height="0"></object></div></body></html>
    可以自己将这个代买粘贴到html里 试试


    2楼2014-04-23 11:13
    收起回复
      亲不要沉啊 求助啊 快来人试试这段代码吧


      3楼2014-04-23 11:22
      回复