Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #24527
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Opacity Problem for IE8 and lower |
| Date | 2014-06-01 13:27 -0300 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <lmfk96$mnr$1@speranza.aioe.org> (permalink) |
| References | <buptfvF1um5U1@mid.individual.net> |
On 29/05/2014 20:17, Mel Smith wrote:
> Hi:
>
> I have the following statement in a function that is supposed to restore
> the default opacity to 1.0 (100 in IE8 and lower) in several 'divs' from
> the opening 40 opacity.
>
> document.getElementById("iMyDivId").style.filter =
> alpha(opacity=100) ;
>
> This gives a JS runtime error
>
> For all other browsers, I use:
>
> document.getElementById("MyDivId").style.opacity = 1.0 ; // works
> correctly
>
>
> Would someone please correct my syntax ?
>
Kangax has made a fork to emile.js to deal with the opacity filter in IE
version <= 8:
<https://github.com/kangax/emile/blob/master/emile.js>
Adapting from Kangax's code, we have:
/** Define the setOpacity() and getOpacity methods at load-time.
* @param {Object} el - an HTMLElement
* @param {Number} val - a Number between 0 and 1.
* Idea adapted from emile.js in conjuction with Kangax's fork
* @see https://github.com/kangax/emile/blob/master/emile.js
*/
var parseEl = document.createElement('div'),
supportsOpacity = typeof parseEl.style.opacity == 'string',
supportsFilters = typeof parseEl.filters != 'undefined',
reOpacity = /alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/i,
setOpacity = function () { };
if (supportsOpacity) { // W3C compliant browsers.
setOpacity = function (el, val) { el.style.opacity = val; };
} else if (supportsFilters) { // IE <= 8
setOpacity = function (el, val) {
var es = el.style, f = es.filter;
// Avoid IE's hasLayout bug by setting zoom to 1 (normal).
if (el.currentStyle && !el.currentStyle.hasLayout) es.zoom = 1;
if (reOpacity.test(f)) {
// Fix IE's clearType bug if v >= 0.9999 => removes opacity
// filter.
val = (val >= 0.9999) ? '' : ('alpha(opacity=' + (val * 100) +
')');
es.filter = f.replace(reOpacity, val);
} else {
es.filter += ' alpha(opacity=' + (val * 100) + ')';
}
};
}
--
Joao Rodrigues
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
Opacity Problem for IE8 and lower "Mel Smith" <syntel@cox.net> - 2014-05-29 17:17 -0600
Re: Opacity Problem for IE8 and lower Ed Jay <edMbj@aes-intl.com> - 2014-05-29 16:56 -0700
Re: Opacity Problem for IE8 and lower "Mel Smith" <syntel@cox.net> - 2014-05-30 07:50 -0600
Re: Opacity Problem for IE8 and lower Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-30 17:27 +0200
Re: Opacity Problem for IE8 and lower Christoph Michael Becker <cmbecker69@arcor.de> - 2014-05-30 17:56 +0200
Re: Opacity Problem for IE8 and lower "Mel Smith" <syntel@cox.net> - 2014-05-30 10:27 -0600
Re: Opacity Problem for IE8 and lower Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-30 22:37 +0200
filter (was: Opacity Problem for IE8 and lower) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-01 14:59 +0200
Re: Opacity Problem for IE8 and lower Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-30 14:32 +0200
Re: Opacity Problem for IE8 and lower Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-06-01 13:27 -0300
csiph-web