14

I have been searching for a way to implement a hover-over popup with no luck. Because it is used on so many sites I thought it would be easy to find instructions, but I am wondering if I am missing something basic. I have looked at qTips2 and a few others, but these seem like way more than I need.

I have a Rails 3.1 app and want to display more details when a user hovers over a line in a table. Is this something built into Rails that I am missing, or do I need an add-on?

I sure would appreciate someone pointing me in the right direction.

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
SteveO7
  • 2,430
  • 3
  • 32
  • 40
  • That would be a simple hovering div. – Sergio Tulentsev Dec 22 '11 at 19:50
  • This isn't a Rails question, but rather a CSS or JavaScript question. – Wizard of Ogz Dec 22 '11 at 19:53
  • Ha! javascript and css tags were added before I could get to it. – Wizard of Ogz Dec 22 '11 at 19:54
  • We'll need a bit more explanation: 1) what do you mean with 'hover-over popup' (just the default browser tooltip, a styleable multiline div,...?) 2) what does your table html look like, and what items should trigger the mouseover? – ptriek Dec 22 '11 at 19:59
  • 1
    This should be marked as a duplicate of e.g. https://stackoverflow.com/questions/3559467/description-box-using-onmouseover, https://stackoverflow.com/questions/18359193/plain-javascript-tooltip or https://stackoverflow.com/questions/11683620/how-to-display-pop-up-text-on-mouse-hover. The currently shown duplicate has been deleted. – Ilmari Karonen Jul 16 '19 at 16:55

2 Answers2

11

Use some CSS and Javascript!

Here's an example you can play with: http://jsfiddle.net/cdpZg/

Copying it here, just in case.

HTML:

<div id='user'>I am a user. Move your mouse over me</div>
<div id='popup'>Extended info about a user</div>
<div>I a piece of useless information. No use hovering over me.</div>

CSS:

#popup {
    height: 50px;
    width: 200px;
    text-align: center;
    vertical-align:middle;
    background-color: cornflowerblue;
    color: white;
    display: none;
    padding-top: 8px;
    position: absolute;
}

Javascript:

$(document).ready(function() {
    $('#user').hover(function() {
        $('#popup').show();
    }, function() {
        $('#popup').hide();
    });
});
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
7

Just set the title on your link like this

<a title="Some text that will show up when I hover over this link">My link</a>
Bassam Mehanni
  • 14,796
  • 2
  • 33
  • 41