Make HTML Elements Semi-Transparent
Internet Explorer does not support the opacity
CSS property like Firefox and Safari. The solution is (as usual) to take advantage of IE filters to acheive a similar effect. This simple function sets opacity/transparency correctly across all modern browsers:
function setOpacity(element, opacity) { if (navigator.userAgent.indexOf("MSIE") != -1) { var normalized = Math.round(opacity * 100); element.style.filter = "alpha(opacity=" + normalized + ")"; } else { element.style.opacity = opacity; } }
This example usage sets the opacity of the given element to 50%:
setOpacity(document.getElementById("image2"), 0.5);
You can also set the opacity properly with static CSS if that is appropriate for your project. This CSS snippet is equivalent to the line of JavaScript above:
#image2 { filter: alpha(opacity=50); opacity: 0.5; }
Comments
http://www.satzansatz.de/cssd/onhavinglayout.html
Your little examples are so clear, it becomes easy !!
Thanksssss
Good work!!!!!
IT WORKED LIKE A CHARM
and
you are a star!
Many thanks,
Ian
thankyou thankyou
what has AJAX to do with transparency?
You are the best teachers.
Cheers
Write a Comment