views:

109

answers:

2

when i try to run this javascript it says that theres an error "INDEX_SIZE_ERR: DOM Exception 1"

Javascript:

blocksize=50;
ctx=document.getElementById('wizard1').getContext('2d');
ctx.drawImage(document.getElementById('wizard.png'),0,0,105,105,0,0,3/7*blocksize,blocksize);

HTML:

<canvas id='wizard1'></canvas>
<img id='wizard.png' src='wizard.png' />
A: 

Try adding width and height attributes on the canvas element (not CSS, actual attributes in the markup). They're used to establish the coordinate system, so that could be the cause. (Untested, though.)

Ms2ger
canvas defaults to 300x150 so thats not an issue
Jcubed
A: 

The wizard.png image wasn't 105px wide, so the drawImage was trying to retrieve data that wasn't there.

Jcubed