Solved

image alpha value

Posted on 2013-05-12
4
279 Views
Last Modified: 2013-05-12
Hi,
I have a image gallery where I display a different image every sec. It works fine but to have a fade in effecgt with javascript this is getting really messy.
Is there an easy way to change the opacity of an image or should I use something other than javacript?

 <canvas id="myCanvas" width="250" height="250"></canvas>
   <script>
  var canvas = document.getElementById('myCanvas');
    var ctx = canvas.getContext('2d');
   var j=0;
	var arr1 = [];
	var images=[];
	var imgLoaded = 0;
	var ii=0;

	arr1[0] = "images/bcave1.png";
	arr1[1] = "images/bcave2.png";
	arr1[2] = "images/bcave3.png";
	arr1[3] = "images/bcave4.png";
	
	 onImgLoad = function()
	{
  	 imgLoaded++;
	
 	  if(imgLoaded == 4) //all loaded
  	 {
  	
		 gameLoop = setInterval(doGameLoop, 1000);
		 
 	  }
	}
	
	  function doGameLoop() {

        ctx.clearRect(0,0,600,400);
        ctx.drawImage(images[ii], 50, 50);
		ii++; 
		//images[ii].x++;
        if (ii==4){
			ii=0;
		}
		
     }

	

	for (i=0;i<arr1.length;i++){
		
		
		images[i] = new Image();
 		images[i].onload = onImgLoad;
 		images[i].src = arr1[i];
		
	}
	
	
	
    </script>

Open in new window

0
Comment
Question by:jagguy
  • 3
4 Comments
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
0
 

Author Comment

by:jagguy
Comment Utility
That works thanks .

I see you are fading the whole canvas but can I  reference the image to fade instead of the whole canvas. I might have many images on the canvas and i dont want to fadein/out the whole canvas but just the image.

Can I also specify a time instead of  $("#myCanvas").fadeIn("slow");//i prefer millsec and not slow

$("#myCanvas").fadeOut("slow", function() {//change

$("images[i]").fadeOut("slow", function() { //to this somehow?

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
take a look, just a look to the links provided
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
I might have many images on the canvas and i dont want to fadein/out the whole canvas but just the image.

For me there's no way, you're painting on it, this is not layers
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now