We can simply use CSS alone to reproduce opacity effect that have traditionally been done using scripting. The advantage of looking to CSS instead is obvious – much more lightweight and easier to implement. We can use this method where we need to use a dim or faint version of image, while when some one places mouse over it, then image comes sharp, clear and bright.

Use the following code in head section of web page.

<style type="text/css">
.opacityit img{
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=40);
-moz-opacity: 0.4;
}
.opacityit:hover img{
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=100);
-moz-opacity: 1;
}
</style>

Use the following code in body where the image is located.

<a href="#" class="opacityit"><img border="0" src="email.gif" /></a>

By this method image loads kind of blur in background and in light colors, but when some one places mouse over it. It becomes sharp.

Simple Opacity

We are using JavaScript to change the opacity of an image here. The technique works in both IE4+ and NS6+, and can be used to create some interesting “fading” effects. Here is the simple way to just place an image with opacity.

<img src="image.gif" style="filter:alpha(opacity=50); -moz-opacity:0.5">

In -moz-opacity:0.5 accepted range of values are 0 to 1, where 0 would make the image disappear and in alpha(opacity=50) range is between 1 to 100. We have combined the code both for IE and Mozilla for code compatibility.

We can also alter the opacity of image using javascript.

Head section code

<script>
function alteropacity(imageobject, opacity){
 if (navigator.appName.indexOf("Netscape")!=-1
  &&parseInt(navigator.appVersion)>=5)
    imageobject.style.MozOpacity=opacity/100
 else if (navigator.appName.indexOf("Microsoft")!= -1 
  &&parseInt(navigator.appVersion)>=4)
    imageobject.filters.alpha.opacity=opacity
}
</script>

Body Section Code

<img src="image.gif" style="filter:alpha(opacity=50); -moz-opacity:0.5" 
onMouseover="alteropacity(this, 100)" onMouseout="alteropacity(this, 30)">

Related Posts

, , , , , , , , ,

One Review

  1. popljubo says:

    CSS method not working in Moz. 3.5.3 but opacity of image using javascript working fine

    ReplyReply

Leave a Review

Incoming Searches

css dim image, javascript how to change opacity of image, javascript dimming images with opacity, javascript dimming image mouseover, java script image dim effect, images mouseover opacity, image css dim, how to opacity use for image fading effect using js, how to change web page opacity, how to change the opacity of an image in adobe flash, how to change the opacity of a section of a website in a css, How to change opacity of picture using javascript, javascript image switch blur, wordpress change picture opacity, javascript opacity change image js, use css to dim percentage of image, progid:DXImageTransform Microsoft make the image sharper, picture bright on mouse over css, opacity in websites, opacity changing using prototype javascript, ms word 2010 change image opacity, making an image disappear using js, make an images opacity change on hover, js opacity switch, Javascript PIcture Comment Opacity, javascript opacity of image changes when page loads, highlight image mouseover dim other images opacity, extjs style == opacity ?, extjs image opacity in, changing the opacity of a body using css, change opacity on twitter widgets, change opacity of an image on a web page, change opacity in a picture, change image opacity onmouseover css, change image opacity, change image color js, change image alpha with javascript, alpha mouseover image javascript chrome, alpha bright in css, ajax Highlight Image onMouseover (Opacity)highlight, css change image bright, css dim image on hover, EXTjs IE problem progid:DXImageTransform Microsoft Alpha, easily using image, dimming images with javascript, dimming image css, dim img css, dim image with javascript, dim image on mouse over wordpress, dim image on hover css, css filter alpha opacity mouseover text image, css diming images, css dim images, -ms-filter: progid:DXImageTransform Microsoft Alpha(Opacity=40); what purpose