Welcome to WebmasterWorld Guest from 50.16.68.229

Forum Moderators: open

DHTML Javascript Graphics

   
2:39 pm on Jun 27, 2003 (gmt 0)

10+ Year Member



Trying to draw a Rectangle on a Layer so I can eventually move it around. This is pretty basic but can't seem to get it to work. The below code should just draw the rectangle on clicking of the button. Please help.

<div id="myCanvas" style="position:relative;height:50%;width:50%;"></div>
<script type="text/javascript" src="wz_jsgraphics.js"></script>

<script type="text/javascript">

var jg = new jsGraphics("myCanvas");

function myDrawFunction()
{
jg.setColor("#00ff00");
jg.fillRect(110, 120, 30, 60);
jg.paint();
}

myDrawFunction();
</script>

<html>

<head>

<title>New Page 1</title>
</head>

<input type="button" value="Button" name="B3" onclick="myDrawFunction()"></p>

</body>

</html>

3:02 pm on Jun 27, 2003 (gmt 0)

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Welcome to the board daddywhite,

Is the code above how the page looks? Are you placing all of that code outside the HTML tag? Why do you have an orphan myDrawFunction() call in the script tag?

I am also assuming that the wz_jsgraphics.js has the object functions like paint()?

7:25 pm on Jun 28, 2003 (gmt 0)

10+ Year Member



I have managed to get it fixed now, thanks anyway for your reply.
The bit I was missing was in capitals below:

<div id="myCanvas" style="position:relative;height:50%;width:50%;">HELLO</div>

For some reason it would not draw anything on the layer until I have some text placed on the layer. Is there a way round this? Rather than having 'HELLO' or whatever on my page?

I have set the colour of this text to white so I cant be seen but even so would like to know why it would not work first time.

Thaanks

 

Featured Threads

Hot Threads This Week

Hot Threads This Month