Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-18-2012, 11:35 PM   PM User | #1
kingkong22
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
kingkong22 is an unknown quantity at this point
Image object problem,

Hi, someone can help plese!!!!

I dont know what happened with the source because after the script executes, there is nothing in the canvas

function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
var img = new Image();

img.onload = function(){
ctx.drawImage(img,0,0);
}
}

img.src = 'images/backdrop.png';

Can someone help please!!!
kingkong22 is offline   Reply With Quote
Old 11-19-2012, 11:21 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
EDIT: You closed the function too early. The img.src line has to go into the function, so just move the last closing bracket } after the img.src line

Code:
function draw() {
   var ctx = document.getElementById('canvas').getContext('2d');
   var img = new Image();

   img.onload = function(){
      ctx.drawImage(img,0,0);
   }
   img.src = 'images/backdrop.png';
}
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:58 AM.


Advertisement
Log in to turn off these ads.