zoukankan      html  css  js  c++  java
  • 滚动条

    var ref = null;
    var c = document.createElement('canvas');//添加一个canvas模块
    c.width = 500;
    c.height = 300;
    c.id = "aaaaa";
    var parent = document.getElementById("box");
    parent.appendChild(c);//在名为 box 的div里添加刚才声明的canvas
    var ctx = c.getContext('2d'),//ad模式
    hue = 0,
    vy = -3,//速度
    par = [],
    x = 0,
    draw = function () {
    var color;
    ctx.clearRect(0,0, c.width, c.height);
    x += 1.5;
    hue = (x > 500)?0:hue;
    color = 'hsla('+(hue++)+',100%,40%,1)';//渐变的颜色
    par.push({//小方块
    px : x + 40,
    py : 50,
    pvy : vy,
    pcolor : 'hsla('+(hue+10)+',100%,40%,1)'
    });
    x = ( x > 500) ? 0 : x;
    ctx.fillStyle = color;
    ctx.fillRect(45,40,x,20);

    var n = par.length;
    while(n--){
    par[n].pvy += (Math.random()+0.1)/5;
    par[n].py += par[n].pvy;
    if (par[n].py > c.height){
    par.splice(n,1);
    continue;
    }
    ctx.fillStyle = par[n].pcolor;
    ctx.fillRect(par[n].px,par[n].py,2,2);
    //ctx.fillStyle = '#222';
    // ctx.fillRect(45, 40, x, 10);
    }
    ref = window.requestAnimationFrame(draw);
    };
    ref = window.requestAnimationFrame(draw);
  • 相关阅读:
    Lightoj 1321 Sending Packets(Bellman-Ford)
    Lightoj 1281 New Traffic System (记忆化Dijkstra)
    NBUT TNT #1 题解报告
    UVA 11624 BFS
    FZU 2150 枚举+BFS
    POJ 3126 BFS
    POJ 3279 DFS
    POJ 1062 dijkstra + 枚举
    lightoj 1123 增量最小生成树
    python 常用算法及解析
  • 原文地址:https://www.cnblogs.com/lyf2458857555/p/6024617.html
Copyright © 2011-2022 走看看