Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change image opacity using javascript

Tags:

javascript

how can I change image opacity using javascript? I'm going to create a fading effect using javascript, is there any sample? is there anything like image.opacity that can be changed through JS code? how is it set?

thanks

like image 742
Ali_dotNet Avatar asked Dec 15 '11 08:12

Ali_dotNet


People also ask

Can you change opacity in JavaScript?

To change the opacity of a HTML Element using JavaScript, get reference to the HTML Element element, and assign required opacity value to the element. style. opacity property. Opacity value ranges from 0 to 1.

What does opacity mean in JavaScript?

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

How do you change opacity of text in JavaScript?

To change the opacity of a paragraph using JavaScript, get the reference to the paragraph element, and assign the specific opacity value to the element. style. opacity property. Opacity value ranges from 0 to 1.

What is opacity in angular?

Definition and UsageThe 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. opacity 0.2. opacity 0.5.


1 Answers

Supposing you're using plain JS (see other answers for jQuery), to change an element's opacity, write:

var element = document.getElementById('id'); element.style.opacity = "0.9"; element.style.filter  = 'alpha(opacity=90)'; // IE fallback 
like image 174
stecb Avatar answered Sep 17 '22 18:09

stecb