homepage Welcome to WebmasterWorld Guest from 54.198.94.76
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
DHTML Javascript Graphics
daddywhite




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

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>

 

korkus2000




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

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()?

daddywhite




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved