离开哈弗的事件

时间:2016-12-04 23:50:01

标签: javascript jquery css

如果我将鼠标悬停在另一个div上,我想降低某些div的不透明度,但如果我停止将div悬停,则不透明度应该再次更改为1

HTML

<div id="feld1" onmouseover="show1()"> </div>
<div id="feld2" onmouseover="show2()"> </div>
<div id="feld3" onmouseover="show3()"> </div>

JS

function show1() {
  if ($('#feld1:hover').length != 0) {
    document.getElementById("feld2").style.opacity = 0.1;
    document.getElementById("feld3").style.opacity = 0.1;
  } else {
    document.getElementById("feld2").style.opacity = 1;
    document.getElementById("feld3").style.opacity = 1;   
  }
}

关于它如何运作的任何想法?

1 个答案:

答案 0 :(得分:1)

好的,我明白了......

document.getElementById("feld1").onmouseover = function() {mouseOver()};
document.getElementById("feld1").onmouseout = function() {mouseOut()};

function mouseOver() {

    document.getElementById("feld2").style.opacity = 0.1;
    document.getElementById("feld3").style.opacity = 0.1;
}

function mouseOut() {
     document.getElementById("feld2").style.opacity = 1;
    document.getElementById("feld3").style.opacity = 1; 
}