我创建了一个非常简单的 javascript 函数,当我将鼠标悬停在某些单词上时,具有某个特定的元素id
变得透明。这适用于我的img
标签,但div
具有相同 id 的 s 没有改变?
这是我的javascript:
function revealCategory1() {
document.getElementById('c2').style.opacity="0.3";
document.getElementById('c3').style.opacity="0.3";
document.getElementById('c4').style.opacity="0.3";
}
function revealCategory2() {
document.getElementById('c1').style.opacity="0.3";
document.getElementById('c3').style.opacity="0.3";
document.getElementById('c4').style.opacity="0.3";
}
function revealCategory3() {
document.getElem..............etc
function resetReveal() {
document.getElementById('c1').style.opacity="1";
document.getElementById('c2').style.opacity="1";
document.getElementById('c3').style.opacity="1";
document.getElementById('c4').style.opacity="1";
}
这个 html 正在调用它:
<div class="bars">
<span class="categories" id="c1" onMouseOver="revealCategory1()" onMouseOut="resetReveal()">VIDEO</span>
<span class="categories" id="c2" onMouseOver="revealCategory2()" onMouseOut="resetReveal()">ANIMATION</span>
<span class="categories" id="c3" onMouseOver="revealCategory3()" onMouseOut="resetReveal()">DESIGN</span>
<span class="categories" id="c4" onMouseOver="revealCategory4()" onMouseOut="resetReveal()">WEB-DESIGN</span>
</div>
在页面上,这工作得很好。图像变得透明。
<div class="logocontainer" >
<img class="logo" id="c1" src="images/DOSED-C1.png" />
<img class="logo" id="c2" src="images/DOSED-C2.png" />
<img class="logo" id="c3" src="images/DOSED-C3.png" />
<img class="logo" id="c4" src="images/DOSED-C4.png" />
</div>
但这不是,div
s 不会透明。
<div class="maincontent">
<div id="c1" class="content" >VIDEO PIECE 1</div>
<div id="c2" class="content" >ANIMATION PIECE 1</div>
<div id="c3" class="content" >DESIGN PIECE 1</div>
<div id="c4" class="content" >WEB-DESIGN PIECE 1</div>
</div>