首页 > Web开发 > 详细

html5 isPointInPath相关操作

时间:2016-02-21 09:04:26      阅读:184      评论:0      收藏:0      [点我收藏+]
<body>
    <canvas id="c1" width="400" height="400">
    </canvas>
    <script type="text/javascript">
        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(x, y, 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>
</body>

 

html5 isPointInPath相关操作

原文:http://www.cnblogs.com/lunawzh/p/5204421.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!