Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript:不透明在opera中有效,但在IE中无效_Javascript_Html_Css - Fatal编程技术网

JavaScript:不透明在opera中有效,但在IE中无效

JavaScript:不透明在opera中有效,但在IE中无效,javascript,html,css,Javascript,Html,Css,我已经使用了以下的图像脚本,它似乎工作得很好;然而,在InternetExplorer中,文本并没有像它应该的那样淡出。有什么想法吗 <td colspan="5" ID='links'> <ul id="navlist"> <li id="active"><a href="#" id="a" onmouseover="over(this)" onmouseout="out()">Apie įmonę</a>|</li&

我已经使用了以下的图像脚本,它似乎工作得很好;然而,在InternetExplorer中,文本并没有像它应该的那样淡出。有什么想法吗

 <td colspan="5" ID='links'>
<ul id="navlist">
    <li id="active"><a href="#" id="a" onmouseover="over(this)" onmouseout="out()">Apie įmonę</a>|</li>
    <li><a href="#" ID="b" onmouseover="over(this)" onmouseout="out()">Naujienos</a>|</li>
    <li><a href="#" ID="c" onmouseover="over(this)" onmouseout="out()">Kainynai</a>|</li>
    <li><a href="#" ID="d" onmouseover="over(this)" onmouseout="out()">Aktyvaus laisvalaikio priemonės</a>|</li>
    <li><a href="#" ID="e" onmouseover="over(this)" onmouseout="out()">Servisas</a>|</li>
    <li><a href="#" ID="f" onmouseover="over(this)" onmouseout="out()">Akcijos</a>|</li>
    <li><a href="#" ID="g" onmouseover="over(this)" onmouseout="out()">Karjera</a>|</li>
    <li><a href="#" ID="h" onmouseover="over(this)" onmouseout="out()">Galerija</a>|</li>
    <li><a href="#" ID="i" onmouseover="over(this)" onmouseout="out()">Naudota technika</a></li>
</ul>
</td>
<script>
var ba = new Array("a","b","c","d","e","f","g","h","i");


function over(from){
var value = 5; 

for(i=0;i<ba.length;i++){

    if(from.id==ba[i])
    {
        //do nothing
    }
    else{
        document.getElementById(ba[i]).style.MozOpacity = value/10;
        document.getElementById(ba[i]).style.opacity = value/10;
        document.getElementById(ba[i]).style.filter = 'alpha(opacity=' + value*10 + ')';

    }
}
}
function out(){
var value = 10;

for(i=0;i<ba.length;i++){

document.getElementById(ba[i]).style.MozOpacity = value/10;
document.getElementById(ba[i]).style.opacity = value/10;
document.getElementById(ba[i]).style.filter = 'alpha(opacity=' + value*10 + ')';
}

}
</script>

  • |
  • |
  • |
  • |
  • |
  • |
  • |
  • |
var ba=新数组(“a”、“b”、“c”、“d”、“e”、“f”、“g”、“h”、“i”); 功能结束(从){ var值=5; 对于(i=0;i检查:

重要部分:“IE8使用了一种新的表示法:
-ms过滤器:“progid:DXImageTransform.Microsoft.Alpha(不透明度=50)”;

另外,Internet Explorer(6和8)似乎认为元素必须显式设置
宽度
,才能透明。奇怪。上面的链接确实使用CSS设置了宽度,但没有提到这个奇怪的要求


(虽然您没有特别询问,但我建议使用jQuery来完成这类任务-它使处理此类效果更加容易,请参见此处:)

我建议创建一个类定义来设置元素的不透明度。然后,在javascript中,您只需编写:

document.getElementById(ba[i]).className = "opacityClassName".
在CSS中,opacityClassName样式定义可以如下所示:

.opacityClassName {
    filter: alpha(opacity:0.5);
    KHTMLOpacity: 0.5;
    MozOpacity: 0.5;
    -khtml-opacity:.50;
    -ms-filter:"alpha(opacity=50)";
    -moz-opacity:.50;
    filter:alpha(opacity=50);
    opacity:.50;
}
这样,您就不必担心以下语法:

document.getElementById(ba[i]).style.ms-filter

不起作用。

使用jQuery。我知道这是一个老生常谈的答案,但在这种情况下,它很正确:它自动为您处理浏览器的怪癖

观察示例:

<table>
<tr>
<td colspan="5" ID='links'>
<ul id="navlist">
    <li id="active"><a href="#" id="a">Apie įmonę</a>|</li>
    <li><a href="#" ID="b">Naujienos</a>|</li>
    <li><a href="#" ID="c">Kainynai</a>|</li>
    <li><a href="#" ID="d">Aktyvaus laisvalaikio priemonės</a>|</li>
    <li><a href="#" ID="e">Servisas</a>|</li>
    <li><a href="#" ID="f">Akcijos</a>|</li>
    <li><a href="#" ID="g">Karjera</a>|</li>
    <li><a href="#" ID="h">Galerija</a>|</li>
    <li><a href="#" ID="i">Naudota technika</a></li>
</ul>
</td>
</tr>
</table>
<script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script><!-- load jQuery -->
<script>
// run when the document is loaded
$(document).ready(function(){

    // give each link under #navlist opacity, unless cursor is over it
    $('#navlist a').mouseover(function(){
        var current = this;
            // run the following for each matching element
        $('#navlist a').each(function(index,element){
            if (element != current) {
                // handles browser quirks for us
                    $(element).css('opacity',0.5);
            }
        });
    });

    // remove the opacity
    $('#navlist a').mouseout(function(event){
        $('#navlist a').each(function(index,element){
            $(element).css('opacity',1);
        });
    });
});

</script>

  • |
  • |
  • |
  • |
  • |
  • |
  • |
  • |
//加载文档时运行 $(文档).ready(函数(){ //在#navlist opacity下指定每个链接,除非光标在其上 $(“#导航列表a”).mouseover(函数(){ 无功电流=此; //为每个匹配的元素运行以下命令 $('#navlista')。每个(函数(索引,元素){ 如果(元素!=当前){ //为我们处理浏览器怪癖 $(元素).css('opacity',0.5); } }); }); //去除不透明度 $('#导航列表a').mouseout(函数(事件){ $('#navlista')。每个(函数(索引,元素){ $(元素).css('opacity',1); }); }); });

跨浏览器工作(Opera、Chromium、Midori、Firefox、IE6和IE8),代码更少,完成任务。时间:15分钟。

Jquery对我来说太多了,现在无法处理:)尝试了一下,但没有成功。我有点困惑,这似乎不起作用:document.getElementById(ba[I]).style.ms-filter='progid:DXImageTransform.Microsoft.Alpha(不透明度='+value*10+');尝试
ms_filter
或msFilter
:JavaScript将
-`视为运算符。我真的认为您需要阅读以下内容: