画格子

      /*
             context    上下文
             color        颜色
             width        线条宽度
             interval    间隔
             type        竖线还是横线
             number        条数
             length     长度
             */
            function lattice(context,color,width,interval,type,number,length){
                var index = 0;
                var lst = window.setInterval(function(){
                    var x = 0;
                    var y = 0;
                    if(type)
                        x=interval*index;
                    else
                        y=interval*index;
                    var ernal = window.setInterval(function() {
                        context.fillStyle = color;
                        context.fillRect(x, y, width, width);
                        var k = !type?++x:++y;
                        console.info("x:"+x);
                        if (k > length) {
                            window.clearInterval(ernal);
                        }
                    },0);
                    index++;
                    if (index >= number) {
                        window.clearInterval(lst);
                    }
                },20);
            }
            lattice(context, "red", 1, 20, true, 51, 1000);
            lattice(context, "red", 1, 20, false, 51, 1000);

posted @ 2013-01-15 19:19  此一生  阅读(139)  评论(0编辑  收藏  举报