Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent image - is it possible in JS?

Is it possible to set transparency of any image in javascript? And how can I do that?

like image 664
oneat Avatar asked Mar 07 '10 13:03

oneat


People also ask

What is transparent in html?

The opacity property sets the opacity level for an element. The opacity-level describes the transparency-level, where 1 is not transparent at all, 0.5 is 50% see-through, and 0 is completely transparent.

What is transparent in image?

With an image or graphic, transparent refers to an image that is clear and can take the effect of any images behind it. Below is an example of the Computer Hope logo with a transparent background. The image is the same but looks different with each of the different colored backgrounds.

What is transparent view?

A see-through display or transparent display is an electronic display that allows the user to see what is shown on the screen while still being able to see through it.

How to make a transparent background color in html?

To set the opacity of a background, image, text, or other element, you can use the CSS opacity property. Values for this property range from 0 to 1. If you set the property to 0, the styled element will be completely transparent (ie. invisible).


2 Answers

If using plain javascript this should work:

function SetOpacity( imageid, opacity ) {
    var s= document.getElementById(imageid).style;
    s.opacity = ( opacity / 100 );
    s.MozOpacity = ( opacity / 100 );
    s.KhtmlOpacity = ( opacity / 100 );
    s.filter = 'alpha(opacity=' + opacity + ')';
}

Call by: SetOpacity('myImg', 50); //Half transparent

Source here

like image 149
Nick Craver Avatar answered Oct 01 '22 22:10

Nick Craver


Yes.

Using jQuery:

$('#yourImageId').css('opacity', .5);
like image 27
SLaks Avatar answered Oct 02 '22 00:10

SLaks