码迷,mamicode.com
首页 > 其他好文 > 详细

h5-9 canvas

时间:2016-04-06 15:01:40      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
</style>
<script>
window.onload = function(){
    var oC = document.getElementById(c1);
    var oGC = oC.getContext(2d);
    
    oGC.fillRect(0,0,100,100);
    
    oGC.fillStyle = red;
    oGC.globalAlpha = 0.5;
    
    oGC.fillRect(50,50,100,100);
    
};
</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
</style>
<script>
window.onload = function(){
    var oC = document.getElementById(c1);
    var oGC = oC.getContext(2d);
    
    oGC.fillRect(0,0,100,100);
    
    oGC.fillStyle = red;
    
    oGC.globalCompositeOperation = xor;
    
    oGC.fillRect(50,50,100,100);
    
};
</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
#img1{ background:white;}
</style>
<script>
window.onload = function(){
    var oImg = document.getElementById(img1);
    var oC = document.getElementById(c1);
    var oGC = oC.getContext(2d);
    
    oGC.fillRect(0,0,100,100);
    
    oGC.fillStyle = red;
    
    oGC.globalCompositeOperation = xor;
    
    oGC.fillRect(50,50,100,100);
    
    //alert( oC.toDataURL() );
    
    oImg.src = oC.toDataURL();
};
</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
<img id="img1" src="" />
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
#img1{ background:white;}
</style>
<script>
window.onload = function(){
    var oImg = document.getElementById(img1);
    var oC = document.getElementById(c1);
    var oGC = oC.getContext(2d);
    
    oGC.beginPath();
    oGC.arc(100,100,50,0,360*Math.PI/180,false);
    oGC.closePath();
    oGC.fill();
    
    oC.onmousedown = function(ev){
        var ev = ev || window.event;
        var x = ev.clientX - oC.offsetLeft;
        var y = ev.clientY - oC.offsetTop;
        
        if( oGC.isPointInPath(x,y) ){
            alert(123);
        }
    };
    
};
</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
<img id="img1" src="" />
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
#img1{ background:white;}
</style>
<script>
window.onload = function(){
    var oImg = document.getElementById(img1);
    var oC = document.getElementById(c1);
    var oGC = oC.getContext(2d);
    
    oGC.beginPath();
    oGC.arc(100,100,50,0,360*Math.PI/180,false);
    oGC.closePath();
    oGC.fill();
    
    oGC.beginPath();
    oGC.arc(200,200,50,0,360*Math.PI/180,false);
    oGC.closePath();
    oGC.fill();
    
    oC.onmousedown = function(ev){
        var ev = ev || window.event;
        var x = ev.clientX - oC.offsetLeft;
        var y = ev.clientY - oC.offsetTop;
        
        if( oGC.isPointInPath(x,y) ){//isPointInPath只作用于最后画出来的oGC
            alert(123);
        }
    };
    
};
</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
<img id="img1" src="" />
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
#img1{ background:white;}
</style>
<script>
window.onload = function(){
    var oImg = document.getElementById(img1);
    var oC = document.getElementById(c1);
    var oGC = oC.getContext(2d);
    
    var c1 = new Shape(100,100,50);
    var c2 = new Shape(200,200,50);
    
    oC.onmousedown = function(ev){
        var ev = ev || window.event;
        var point = {
            x : ev.clientX - oC.offsetLeft,
            y : ev.clientY - oC.offsetTop
        };
        c1.reDraw(point);
        c2.reDraw(point);
    };
    
    c1.click = function(){
        alert(123);
    };
    
    c2.click = function(){
        alert(456);
    };
    
    function Shape(x,y,r){//构造函数
        this.x = x;
        this.y = y;
        this.r = r;
        oGC.beginPath();
        oGC.arc(this.x,this.y,this.r,0,360*Math.PI/180,false);
        oGC.closePath();
        oGC.fill();
    }
    Shape.prototype.reDraw = function(point){//构造函数添加方法
        oGC.beginPath();
        oGC.arc(this.x,this.y,this.r,0,360*Math.PI/180,false);
        oGC.closePath();
        oGC.fill();
        if( oGC.isPointInPath(point.x,point.y) ){
            this.click();
        }
    };
};
</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
<img id="img1" src="" />
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
</style>
<script type="text/javascript" src="jCanvaScript.1.5.18.min.js"></script>   //画布的js
<script>
window.onload = function(){
    
    var oC = document.getElementById(c1);
    var oGC = oC.getContext(2d);
    
    jc.start(c1,true);  //开始,第二个参数:代表重绘的意思,只有重绘了才有点击事件。
    
    //jc.rect(100,100,50,50,‘#ff0000‘,1);//画矩形
    jc.circle(100,100,50,#ff0000,1).click(function(){//画园,1表示填充,0表示不填充。
        alert(123);
    });
    
    jc.start(c1);//闭合

};
</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
</style>
<script type="text/javascript" src="jCanvaScript.1.5.18.min.js"></script>
<script>
window.onload = function(){
    
    var oC = document.getElementById(c1);
    var oGC = oC.getContext(2d);
    
    jc.start(c1,true);  //第二个参数:代表重绘的意思
    
    //jc.rect(100,100,50,50,‘#ff0000‘,1);
    jc.circle(100,100,50,#ff0000,1).draggable();//拖拽了就可以拖着走了
    
    jc.start(c1);

};
</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
</style>
<script type="text/javascript" src="jCanvaScript.1.5.18.min.js"></script>
<script>
window.onload = function(){
    var oInput = document.getElementById(input1);
    var oC = document.getElementById(c1);
    var oGC = oC.getContext(2d);
    
    jc.start(c1,true);  //第二个参数:代表重绘的意思
    
    //jc.rect(100,100,50,50,‘#ff0000‘,1);
    jc.circle(100,100,50,#ff0000,1).id(c11);//给js加id为c11
    
    jc.start(c1);//关闭,相当于close.
    
    oInput.onclick = function(){
        
        jc(#c11).color(#ffff00);//通过#c11确定上面的js
        
    };

};
</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
<input type="button" value="点击" id="input1" />
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
</style>
<script type="text/javascript" src="jCanvaScript.1.5.18.min.js"></script>
<script>
window.onload = function(){
    var oInput = document.getElementById(input1);
    var oC = document.getElementById(c1);
    var oGC = oC.getContext(2d);
    
    jc.start(c1,true);  //第二个参数:代表重绘的意思
    
    //jc.rect(100,100,50,50,‘#ff0000‘,1);
    jc.circle(100,100,50,#ff0000,1).id(c1);
    
    jc.start(c1);
    
    oInput.onclick = function(){
        
        jc(#c1).color(#ffff00).animate({x:200,y:200,radius:5},2000);//{x:200,y:200,radius:5}是一个json,radius表示半径变成5,
        
    };

};
</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
<input type="button" value="点击" id="input1" />
</body>
</html>

 

h5-9 canvas

标签:

原文地址:http://www.cnblogs.com/yaowen/p/5358949.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!