Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show DIV on MouseOver

On mouseover can this div be attached to the mouse pointer so that its contents are shown on mouseover?

<div id='show' style='display:none;'></div>

If so how is this done?

like image 595
Hulk Avatar asked May 24 '26 14:05

Hulk


2 Answers

<div onmousemove="position();" onmouseout="hide();">abc</div>
<div id="tip" style="position: fixed; visibility: hidden;">that's abc!</div>
<script type="text/javascript">
  function position() {
    var d = document.getElementById('tip');
    d.style.visibility = 'visible';
    d.style.left = event.screenX + 'px';
    d.style.top = event.screenY + 'px';
  }
  function hide() {
    document.getElementById('tip').style.visibility = 'hidden';
  }
</script>

When the user mouses over the "abc" div, the "that's abc!" div is shown next to the mouse cursor (and follows it).

like image 133
Max Shawabkeh Avatar answered May 27 '26 04:05

Max Shawabkeh


Try this:

<div id='show' onmouseover="this.style.display = 'block';"></div>

But for that to work, the div should be visible first. However, if the div is hiddne (display:none) then onmoueever event won't be able to find the div and no event will be triggered on it. Having said that, try this which uses visibility property.

<div id='show' onmouseover="this.style.visibility = 'visible';"  onmouseout="this.style.visibility = 'hidden';"></div>
like image 44
Sarfraz Avatar answered May 27 '26 04:05

Sarfraz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!