美文网首页
JS:day07

JS:day07

作者: AnnQi | 来源:发表于2017-08-10 18:59 被阅读0次

    一、className属性

    给元素添加一个新的class属性,

        var test=document.getElementById("test");
        test.onclick=function(){
            console.log(1);
            /*给当前元素增加一个class属性*/
            addClass(this,"click")
        };
        function addClass(element,value){
            if(!element.className){
                element.className = value;
            }else{
                var newClassName = element.className;
                newClassName += " ";
                newClassName += value ;
                element.className = newClassName;
            }
        }
    

    二、HTML5 创建画布

    function draw(){
            var canvas = document.getElementById("draw-in-me");
            if(canvas.getContext){
                var ctx = canvas.getContext("2d");
                ctx.beginPath();
                ctx.moveTo(120.0,32.0);
                ctx.bezierCurveTo(120.0,36.4,116.4,40.0,112.0,40.0);
                ctx.lineTo(8.0,40.0);
                ctx.bezierCurveTo(3.6,40.0,0.0,36.4,0.0,32.0);
                ctx.lineTo(0.0,8.0);
                ctx.bezierCurveTo(0.0,3.6,3.6,0.0,8.0,0.0);
                ctx.lineTo(112.0,0.0);
                ctx.bezierCurveTo(116.4,0.0,120.0,3.6,120.0,8.0);
                ctx.lineTo(120.0,32.0);
                ctx.closePath();
                ctx.fill();
                ctx.lineWidth = 2.0;
                ctx.strokeStyle = "rgb(255,255,255)";
                ctx.stroke();
            }
        }
        draw();
    

    相关文章

      网友评论

          本文标题:JS:day07

          本文链接:https://www.haomeiwen.com/subject/ppfkrxtx.html