I'm trying to fade in an image, but it doesn't work. I found this post: Javascript fade image in and out And tried the following code, but no luck :(
var anImage= new Image();
anImage.src='images\\anImage.gif'
jQuery(function(){$("anImage").fadeIn()})
anImage.fadeIn()
But I get the "Uncaught TypeError: Object # has no method 'fadeIn'" error. I must be doing something wrong. But I'm not seeing it :s. Please help,
Thanks in advance
================================================================================== My code looks now like this:
var deadImg= new Image();
deadImg.src='images/dead.gif'
deadImg.id= 'imageID'
deadImg.style.display = 'none'
jQuery('body').append(deadImg);
And I wrote a function, which should draw the image (fade it in on the canvas)
function deadScreen(){
GameOverSound.play();
jQuery('#deadImg.id').fadeIn();
}
But nothing is really happening. Am I doing something wrong?
==================================================================================
EDIT3:
function deadScreen(){
GameOverSound.play();
//increase the context.globalAlpha 0% ->100% and draw image
context.globalAlpha= 0%->100%
context.drawImage(deadImg,0,0,canvas.width,canvas.height);
//at the end make sure nothing is transparant!
context.globalAlpha=1
}
Can I do something like this? I thought using a for loop or something to increase transparancy from full transparant to not transparant. And with each step, redraw the image. Or isn't this a good idea?
============================================================================
Thank you everybody for your help. I solved the problem by increasing the globaltransparancy and redrawing the image. This is without jQuery and inside the canvas.
But still thank you very much to the people who helped me :)