This is the web log of Tim Bennett, web designer. He also runs Texelate, offering the best web design Leeds, Yorkshire has to offer

Cross browser JavaScript image opacity changing function

Wednesday, July 11th, 2007 at 8:25 am

This bit of code will let you change the opacity of an image using JavaScript; unlike most scripts it works on Safari and Opera as well as IE and Firefox. Simple send the id of the image and a value between 0 and 100 to change the opacity (0 being invisible and 100 fully visible).

function changeopacity( imageobject, opacity ) {

    var object = imageobject.style;

    object.opacity = ( opacity / 100 );

    object.MozOpacity = ( opacity / 100 );

    object.KhtmlOpacity = ( opacity / 100 );

    object.filter = “alpha(opacity=” + opacity + “)”;

 

}

One Response to “Cross browser JavaScript image opacity changing function”

  1. admin says:

    I’ve tested this in IE6, IE7, Firefox, Opera and Safari.

Leave a Reply

You must be logged in to post a comment. If you don't have an account register one now.

Do you need a website or web-related service?
I run an award-winning web design studio.