需要在其他div的悬停时显示div

时间:2015-01-27 19:16:38

标签: javascript html css

我有一个元素设置为可见性:隐藏,我需要它在悬停时更改为可见,我尝试使用javascript没有运气

HTML

<div class="options">
  <div id="option-1" onmouseover="dis()"></div>
  </div>
</div>
<div id="pic-1"></div>

CSS

#option-1{
  width:100px;
  height:20px;
  background:#fff;
  position:relative;
  z-index:999;
  top:0;left:0;
}
#pic-1{
  width:100%;
  height:100%;
  position:absolute;
  z-index:99;
  background:#f0f;
  visibility:hidden;
}

的Javascript

function dis(){
  document.getElementById("pic-1").style.visibility = "visible";
}

1 个答案:

答案 0 :(得分:2)

HTML:

<div class="options">
  <div id="option-1" onmouseover="showx();"  onmouseout="hidex();"></div>
  </div>
</div>
<div id="pic-1"></div>

的CSS:

#option-1{
  width:100px;
  height:100px;
  background-color:red;
  cursor: pointer;
}
#pic-1{
  width:100%;
  height:100%;
  position:absolute;
  z-index:99;
  background:#f0f;
  visibility:hidden;
}

JS

function showx(){
  document.getElementById("pic-1").style.visibility = "visible";
}

function hidex(){
  document.getElementById("pic-1").style.visibility = "hidden";
}

codepen link:http://codepen.io/anon/pen/bNrdrN