この JavaScript コードでは、一連の画像のリンクをダウンロードし、それらをグリッド テーマのキャンバスに描画します。リンクの数を取得し、それに応じてキャンバスの幅と高さを設定すると、1 行あたり 200 個の画像が表示されます。高さは画像の総数に基づいています。私が気づいている問題は、使用する高さに基づいて、画像がキャンバスに表示されることです。たとえば、高さを 12 行に設定すると画像が表示されますが、それ以上に設定すると画像が表示されません。また、1行に設定しても画像はFirefox 23でしか表示されません。IE9とchrome29では何も表示されません。
ここに何か問題があるかどうか、または多くの画像を大きなキャンバスに安定して描画する方法を知っている人はいますか?
ありがとう。
function onProfileSuccessMethod(sender, args) {
alert("Request Arrived");
var listEnumerator, picCount, item, picobj, path, office, ctx, x, y, imageObj;
listEnumerator = listItems.getEnumerator();
picCount = listItems.get_count();
var w = 125;
var h = 150;
var rl = 200;
var canvas = document.createElement('canvas');
canvas.id = "picGallery";
canvas.width = w * rl;
canvas.height = h * 12// * Math.ceil(picCount/rl);
canvas.style.zIndex = 0;
canvas.style.border = "0px solid white";
context = canvas.getContext("2d");
x = 0;
y = 0;
while (listEnumerator.moveNext()) {
item = listEnumerator.get_current();
picobj = item.get_item('Picture');
office = item.get_item('Office');
office = office == null ? "" : office;
if (picobj != null) {
path = picobj.get_url();
imageObj = new Image();
imageObj.xcoor = x;
imageObj.ycoor = y;
imageObj.src = path;
imageObj.onload = function() {
context.drawImage(this, this.xcoor, this.ycoor, w, h);
};
}
x += w;
if (x == canvas.width) {
x = 0;
y += h;
}
}
document.body.appendChild(canvas);
}