在 IE7 中设置动态生成元素的不透明度
我正在 js 中创建一个 div 并设置它的不透明度。这在 IE8 中没有问题:
var div = document.createElement("div");
div.setAttribute("style", "opacity: 0; visibility: hidden; filter: alpha(opacity=0)");
该元素淡入/淡出,在 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 为创建的。没有报告错误。所以我尝试了这个:
div.filters = 'alpha(opacity=0)';
哪些错误“对象不支持此属性或方法”。我也尝试过设置 Zoom: 1 但也无济于事。有什么建议吗?
谢谢
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)");
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 {
.....
}
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)';
which errors "Object does not support this property or method". I also tried setting zoom: 1 but also to no avail. Any suggestions?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信 IE7 在 JS 中的格式更像是:
I believe the format for IE7 in JS is more like:
需要注意的是,如果不设置宽度,Alpha 过滤器将无法在 IE7 中工作。这是一个来之不易的发现。
It is important to note that the alpha filter will not work in IE7 without also setting the width. This was a hard-earned discovery.