在IE7中设置动态生成的元素的不透明度 [英] Setting opacity of dynamically generated element in IE7

查看:68
本文介绍了在IE7中设置动态生成的元素的不透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在js中创建一个div并将其设置为不透明.在IE8中这没问题:

I'm creating a div in js and setting it's opacity. This works no problem in IE8:

var div = document.createElement("div");
div.setAttribute("style", "opacity: 0; visibility: hidden; filter: alpha(opacity=0)");

此元素淡入/淡出,在IE8中也很好用:

This element fades in/out, which also works great in IE8:

if (_SU3.browser == "IE") {

    var op = element.filters.alpha.opacity;
    var newOpacity = op - (opacityStep * 100);

    if (newOpacity <= 0) {
        element.filters.alpha.opacity = 0;
        element.style.visibility = "hidden";
    } else {
        element.filters.alpha.opacity = newOpacity;
        _SU3.timeouts[url] = setTimeout(function() { _SU3.fadeOut(element, opacityStep); }, 100); 
    }

} else {

       .....
}

但是它在IE7中不起作用:从开发人员工具(F12)看来,创建div时未设置样式.没有错误报告.所以我尝试了这个:

But it doesn't work in IE7: from the developer tool (F12) it looks like the styles are not being set when the div is created. No errors are reported. So I have tried this:

div.filters = 'alpha(opacity=0)';  

哪个错误对象不支持此属性或方法".我也尝试设置缩放:1,但也无济于事.有什么建议吗?

which errors "Object does not support this property or method". I also tried setting zoom: 1 but also to no avail. Any suggestions?

谢谢

推荐答案

我相信JS中IE7的格式更像是:

I believe the format for IE7 in JS is more like:

element.style.filter = "alpha(opacity="+ value +")"

这篇关于在IE7中设置动态生成的元素的不透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆