0

i have a requirement that I need to create a canvas and draw inside it programattically and put it inside a marquee, all these through javascript. Is it possible ? a few pointers please

As a follow-up: i wrote the following, it creates the canvas but does not scrolll it, but the hard coded marquee works !

<html>
<head>
<meta http-equiv="Content-Script-Type" content="text/javascript">
</head>
<body>
<marquee>you are welcome</marquee>

<input type="button" value="click" name="btn" onClick="btnClicked();"/>



<script>
function btnClicked()
{
alert('here');
var canvas = document.createElement('canvas');
      context = canvas.getContext('2d');      
// Draw whatever on your canvas  
context.beginPath();
context.moveTo(70, 140);
context.lineTo(140, 70);
context.stroke();
var div = document.createElement('div');
div.appendChild(canvas);
var marquee = document.createElement('marquee');  
marquee.appendChild(div);  
document.body.appendChild(marquee);
}
</script>
</body>
</html>
1
  • 2
    It only works if you wrap all that in a blink element. Commented Mar 21, 2011 at 13:48

1 Answer 1

1

It is possible, though probably ugly.

I'll take your question literally...

var canvas = document.createElement('canvas'),

    context = canvas.getContext('2d');

    // Draw whatever on your canvas

var marquee = document.createElement('marquee');

marquee.appendChild(canvas);

document.body.appendChild(marquee);
Sign up to request clarification or add additional context in comments.

2 Comments

looks fine, thanks, but assuming that my page is loaded, when i do this on a button click, will it appear immidiately in the page, as in vb applications ? secondly, can i delete / remove this canvas after the scroll is over ?
@sunu Sorry, I couldn't understand what you meant. If it is a new question, ask a new question and someone else may be able to assist you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.