JCanvasを使用してキャンバスにレイヤーを追加できません

StackOverflow https://stackoverflow.com/questions/8383875

  •  28-10-2019
  •  | 
  •  

質問

JCanvasを使用してHTMLにペイントしています canvas エレメント。最初にax * xテーブルを初期化し、各セルがキャンバスを保持しています。

function init(size) {
            // Adding the board table to the body
            $("#content").append("<table class=\"board\">");

            for(i=0; i<size; i++) {
                $(".board").append("<tr>")
                for(j=0; j<size ; j++) {
                    $(".board tr:last-child").append("<td class=\"square\">");
                }
            }
            // Setting size to match width or height, whichever i smallest
            var h = $("#content").height();
            var w = $("#content").width();
            var rez = (w > h) ? h : w;
            var cSize = rez / size;
            $(".board td").append("<canvas width="+cSize+" height="+cSize+" />");
            $(".board").css("width",rez);
            $(".board").css("height",rez);

            // Drawing icons on the board
            var c = $("canvas");
            var icns = new Array(11);
            for(i=0; i<11; i++)
                icns[i] = "svg/"+ params["hvor"] +"/"+ (i+1) +".svg";

            for(i=0; i<c.length; i++) {
                var rand = Math.floor(Math.random()*(icns.length-1));
                var icn = icns[rand];
                icns.splice($.inArray(icns[rand], icns), 1);
                $(c[i]).drawImage({
                    source: icn,
                    height: cSize,
                    fromCenter: false
                });
            }
        }

これは正常に機能し、画像はキャンバスに描かれます。次に、新しい形状のレイヤーを追加しようとします(後で削除する必要があります。そのため、レイヤーを使用しています)。

$('td').click(function(){
    var h = $(this).height() -2;
var o = h / 3.5;
var t = h / 10;

$(this).children("canvas").addLayer({
    method: "drawLine",
    strokeStyle: "#5cfe15",
    strokeWidth: t,
    x1: o, y1: o*2,
    x2: h/2, y2: h-o,
    x3: o*3, y3: o-t
});
});

それは私がエラーを取得するときです Uncaught TypeError: Object [object Object] has no method 'addLayer'. 。私がただ使用する場合 drawLine() それ以外の addLayer() 実際に線を描くので、オブジェクトは明らかにキャンバスです。

ここに何が欠けていますか?

役に立ちましたか?

解決

jQueryコレクション(つまり、$ .fn)にaddlayer()メソッドを導入したため、Jcanvas v5.0を使用していることを確認してください。

-caleb

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top