2009
Mar
08

Opacity Setting

With CSS

Example
  1. .opacity {
  2. opacity: 0.5; /* For Newer Mozilla Browsers, Safari, and Opera */
  3. -moz-opacity: 0.5 /* For Older Mozilla Browsers, like Netscape Navigator */
  4. -khtml-opacity: 0.5; /* For Older Safari */
  5. -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(opacity=50)"; /* For IE 8 */
  6. filter: alpha(opacity=50); /* For IE 6 and IE 7 */
  7. }

With JavaScript

Example
  1. var setOpacity = function(element, value) {
  2. element.style.opacity = value / 100; /* For Newer Mozilla Browsers, Safari, and Opera */
  3. element.style.MozOpacity = value / 100; /* For Older Mozilla Browsers, like Netscape Navigator */
  4. element.style.KhtmlOpacity = value / 100; /* For Older Safari */
  5. element.style.MsFilter = '"progid:DXImageTransform.Microsoft.Alpha(opacity=' + value + ')"'; /* For IE8 */
  6. element.style.filter = "alpha(opacity=" + value + ")"; /* For IE 6 and IE7 */
  7. };

Related Posts


回應 (Leave a comment)