zoukankan      html  css  js  c++  java
  • html5 isPointInPath相关操作

    <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>

     使用习惯了html中的click等事件,用isPointInPath()这个方法感觉还是很不方便,有没有像jquery那样的方便链式操作,答案是有,有人已经把canvas的事件操作封装成库,这就是jCanvasScript.js。

  • 相关阅读:
    Collections集合工具类排序
    集合的学习
    gitee使用方法
    vue 首屏优化
    vue 配置多个路由别名
    vue中的状态管理Vuex
    【Python】Pandas合并表格之(append, join , concat方法)
    elementui中提交表单自动刷新页面的问题
    滴滴实习面试题
    CSS 日常积累
  • 原文地址:https://www.cnblogs.com/lunawzh/p/5204421.html
Copyright © 2011-2022 走看看