Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript - change the alpha of an image

How can I change the alpha of an image in javascript? Also, what browsers support this?

like image 460
Kyle Avatar asked May 03 '10 19:05

Kyle


2 Answers

Using jQuery:

$(something).css('opacity', 0.5);

This will work in every browser.
However, it will not work properly with semi-transparent PNG images in IE 7 and 8 unless they are applied using a filter.

like image 173
SLaks Avatar answered Nov 08 '22 15:11

SLaks


I don't think you can change the alpha of the image itself, but you can change it from the tag, or the container in which you put it.

The particular css properties I use for this are :

filter:alpha(opacity=50);
-moz-opacity: 0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
like image 41
Francisco Soto Avatar answered Nov 08 '22 14:11

Francisco Soto