Description Box using “onmouseover”

后端 未结 6 1932
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 07:35

I am playing with the onmouseover event in javascript

I would like a little box to pop up and remain up until there is no onmouseover anymo

相关标签:
6条回答
  • 2020-12-08 07:47

    The CSS Tooltip allows you to format the popup as you like as any div section! And no Javascript needed.

    0 讨论(0)
  • 2020-12-08 07:53

    Assuming popup is the ID of your "description box":

    HTML

    <div id="parent"> <!-- This is the main container, to mouse over -->
    <div id="popup" style="display: none">description text here</div>
    </div>
    

    JavaScript

    var e = document.getElementById('parent');
    e.onmouseover = function() {
      document.getElementById('popup').style.display = 'block';
    }
    e.onmouseout = function() {
      document.getElementById('popup').style.display = 'none';
    }
    

    Alternatively you can get rid of JavaScript entirely and do it just with CSS:

    CSS

    #parent #popup {
      display: none;
    }
    
    #parent:hover #popup {
      display: block;
    }
    
    0 讨论(0)
  • 2020-12-08 07:56

    I'd try doing this with jQuery's .hover() event handler system, it makes it easy to show a div with the tooltip when the mouse is over the text, and hide it once it's gone.

    Here's a simple example.

    HTML:

    ​<p id="testText">Some Text</p>
    <div id="tooltip">Tooltip Hint Text</div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
    

    Basic CSS:

    ​#​tooltip {
    display:none;
    border:1px solid #F00;
    width:150px;
    }​
    

    jQuery:

    $("#testText").hover(
       function(e){
           $("#tooltip").show();
       },
       function(e){
           $("#tooltip").hide();
      });​​​​​​​​​​
    
    0 讨论(0)
  • 2020-12-08 08:00

    This an old question but for people still looking. In JS you can now use the title property.

    button.title = ("Popup text here");
    
    0 讨论(0)
  • 2020-12-08 08:05

    Although not necessarily a JavaScript solution, there is also a "title" global tag attribute that may be helpful.

    <a href="https://stackoverflow.com/questions/3559467/description-box-on-mouseover" title="This is a title.">Mouseover me</a>
    

    Mouseover me

    0 讨论(0)
  • 2020-12-08 08:14

    Well, I made a simple two liner script for this, Its small and does what u want.

    Check it http://jsfiddle.net/9RxLM/

    Its a jquery solution :D

    0 讨论(0)
提交回复
热议问题