简体   繁体   English

过滤不透明度IE8

[英]Filter Opacity IE8

I ma trying to set the opacity of an element. 我试图设置元素的不透明度。 I am setting it to 0 and it hovers under the mouse pointer which is used for some pretty advanced click tracking. 我将其设置为0,并将其悬停在用于某些高级点击跟踪的鼠标指针下方。

Works fine in all browsers apart from IE. 在IE之外的所有浏览器中都能正常工作。 In IE 8 when filter opacity is set to 0 the element acts as if its display:none. 在IE 8中,当过滤器不透明度设置为0时,元素的行为就像其display:none一样。 I've also tried using: 我也尝试过使用:

$('#tracking').css('opacity',0)

I thought doing it that way might work, but does the same. 我认为以这种方式执行此操作可能会起作用,但仍会这样做。

Firefox, Chrome, Safari etc use 'Opacity' where as IE uses 'Alpha'. Firefox,Chrome,Safari等使用“不透明度”,而IE使用“ Alpha”。

Just set both styles: 只需设置两种样式:

$('#tracking').css('opacity',0) $('#tracking').css('alpha',0) $('#tracking')。css('opacity',0)$('#tracking')。css('alpha',0)

you get the idea... 你明白了...

Im not using Jquery, so I don't know if these code is useful to you. 我没有使用Jquery,所以我不知道这些代码对您是否有用。 But it works. 但这有效。

function getOpacity(target){
    if(target.currentStyle)
    {
        if(!target.filters.alpha) target.style.filter = "alpha(opacity=100)";
        return Number(target.filters.alpha.opacity) / 100;
    }else{
        return Number(document.defaultView.getComputedStyle(target,null).opacity);
    }
}

function setOpacity(target,opacity){
    if(target.style.opacity || target.style.opacity == "")
    {
        target.style.opacity = opacity;
    }else if(target.style.filter || target.style.filter == "")
    {
         target.filters.alpha.opacity = parseInt(opacity * 100);
        }

}

With jQuery you can also use fadeTo, to make things fade. 使用jQuery,您还可以使用fadeTo使事物淡化。 I don't know if this is handy in your situation, but you can create beautiful websites with it: 我不知道这是否适合您的情况,但是您可以使用它创建漂亮的网站:

$("#myelement").stop().fadeTo('fast', 0.000001);

This also works in Internet Explorer. 在Internet Explorer中也可以使用。 More info: http://api.jquery.com/fadeTo/ 更多信息: http : //api.jquery.com/fadeTo/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM