views:

23125

answers:

13
+12  Q: 

JQuery Popup Bubble

Hello all,

I'm trying to make a "bubble" that can popup when the onmouseover event is fired and will stay open as long as the mouse is over the item that threw the onmouseover event OR if the mouse is moved into the bubble. My bubble will need to have all manners of html and styling including hyperlinks, images, etc.

I've basically accomplished this by writing about 200 lines of ugly javascript but I would really like to find a nice JQuery plugin to clean this up a bit. I did some searching and couldn't find anything to suit my fancy.

Does anyone know of a good JQuery plugin for doing fancy bubbles? Please let me know if you have any questions or need more information and I'd be happy add more!

+1  A: 

Sounds to me you dn't want the mouse over events: you want the jQuery hover() event.

And what you seem to want is a "rich" tooltip, in which case I suggest jQuery tooltip. With the bodyHandler option you can put arbitrary HTML in.

cletus
Hey, thanks for the super-quick response! I just skimmed through the documentation and I'm not sure there is an option to for the "tooltip" to stay in a fixed position so that you can move your mouse onto it and click a link. Have you used this before? In the meantime I'll download and start playing
jakejgordon
+8  A: 

This can be done easily with the mouseover event as well. I've done it and it doesn't take 200 lines at all. Start with triggering the event, then use a function that will create the tooltip;

 $('span.clickme').mouseover(function(event) {
      createTooltip.call(this, event);

 }).mouseout(function(){
    // create a hidefunction on the callback if you want
    //hideTooltip(); 
 });

function createTooltip(event){

    $('<div class="tooltip">test<div>').appendTo('body');
    positionTooltip(event);

};

Then you create a function that position the tooltip with the offset position of the DOM-element that triggered the mouseover event, this is doable with css.

function positionTooltip(event){
     var tPosX = event.pageX  -10;
     var tPosY = event.pageY -100;
     $('div.tooltip').css({top: tPosY, left: tPosX});
};
still checking this out... definately looks promising. I'll update sometime this afternoon when I'm doing testing. Thanks!!
jakejgordon
+2  A: 

Ok, after some work I'm able to get a "bubble" to pop up and go away at all the right times. There is a LOT of styling that needs to happen still but this is basically the code i used.

<script type="text/javascript">
    //--indicates the mouse is currently over a div
    var onDiv = false;
    //--indicates the mouse is currently over a link
    var onLink = false;
    //--indicates that the bubble currently exists
    var bubbleExists = false;
    //--this is the ID of the timeout that will close the window if the user mouseouts the link
    var timeoutID;

    function addBubbleMouseovers(mouseoverClass) {
        $("."+mouseoverClass).mouseover(function(event) {
            if (onDiv || onLink) {
                return false;
            }

            onLink = true;

            showBubble.call(this, event);
        });

        $("." + mouseoverClass).mouseout(function() {
            onLink = false;
            timeoutID = setTimeout(hideBubble, 150);
        });
    }

    function hideBubble() {
        clearTimeout(timeoutID);
        //--if the mouse isn't on the div then hide the bubble
        if (bubbleExists && !onDiv) {
             $("#bubbleID").remove();

             bubbleExists = false;
        }
    }

    function showBubble(event) {
        if (bubbleExists) {
            hideBubble();
        }

        var tPosX = event.pageX + 15;
        var tPosY = event.pageY - 60;
        $('<div ID="bubbleID" style="top:' + tPosY + '; left:' + tPosX + '; position: absolute; display: inline; border: 2px; width: 200px; height: 150px; background-color: Red;">TESTING!!!!!!!!!!!!</div>').mouseover(keepBubbleOpen).mouseout(letBubbleClose).appendTo('body');

        bubbleExists = true;
    }

    function keepBubbleOpen() {
        onDiv = true;
    }

    function letBubbleClose() {
        onDiv = false;

        hideBubble();
    }


    //--TESTING!!!!!
    $("document").ready(function() {
        addBubbleMouseovers("temp1");
    });
</script>

Here is a snippet of the html that goes with it:

<a href="" class="temp1">Mouseover this for a terribly ugly red bubble!</a>
jakejgordon
+1  A: 

Remy Sharp @ jQuery for Designer did a screencast about making a Bubble like the one on the Coda site and that takes you through the whole process - including keeping the bubble active whilst moving mouse from original launch location over the bubble, and back.

http://jqueryfordesigners.com/coda-popup-bubbles/

Kristen
A: 

Autoresize simple Popup Bubble

index.html

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;
&lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;link href="bubble.css" type="text/css" rel="stylesheet"/&gt;
  &lt;script language="javascript" type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
  &lt;script language="javascript" type="text/javascript" src="bubble.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;br/&gt;&lt;br/&gt;
  &lt;div class="bubbleInfo"&gt;
      &lt;div class="bubble" title="Text 1"&gt;Set cursor&lt;/div&gt;
  &lt;/div&gt;
  &lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;
  &lt;div class="bubbleInfo"&gt;
      &lt;div class="bubble" title="Text 2"&gt;Set cursor&lt;/div&gt;
  &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

bubble.js

$(function () {

  var i = 0;
  var z=1;
  do{
    title = $('.bubble:eq('+i+')').attr('title');
    if(!title){
      z=0;
    } else {
       $('.bubble:eq('+i+')').after('&lt;table style="opacity: 0; top: -50px; left: -33px; display: none;" id="dpop" class="popup"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td id="topleft" class="corner"&gt;&lt;/td&gt;&lt;td class="top"&gt;&lt;/td&gt;&lt;td id="topright" class="corner"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="left"&gt;&lt;/td&gt;&lt;td&gt;'+title+'&lt;/td&gt;&lt;td class="right"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="corner" id="bottomleft"&gt;&lt;/td&gt;&lt;td class="bottom"&gt;&lt;img src="bubble/bubble-tail.png" height="25px" width="30px" /&gt;&lt;/td&gt;&lt;td id="bottomright" class="corner"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;');
       $('.bubble:eq('+i+')').removeAttr('title');
    }
    i++;
  }while(z&gt;0)

  $('.bubbleInfo').each(function () {
    var distance = 10;
    var time = 250;
    var hideDelay = 500;

    var hideDelayTimer = null;

    var beingShown = false;
    var shown = false;
    var trigger = $('.bubble', this);
    var info = $('.popup', this).css('opacity', 0);


    $([trigger.get(0), info.get(0)]).mouseover(function () {
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      if (beingShown || shown) {
        // don't trigger the animation again
        return;
      } else {
        // reset position of info box
        beingShown = true;

        info.css({
        top: -40,
        left: 10,
        display: 'block'
        }).animate({
        top: '-=' + distance + 'px',
        opacity: 1
        }, time, 'swing', function() {
          beingShown = false;
          shown = true;
        });
      }

      return false;
    }).mouseout(function () {
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        info.animate({
        top: '-=' + distance + 'px',
        opacity: 0
        }, time, 'swing', function () {
          shown = false;
          info.css('display', 'none');
          });
      }, hideDelay);
      return false;
    });
  }); 
});

bubble.css

/* Booble */
.bubbleInfo {
    position: relative;
    width: 500px;
}
.bubble {

}
.popup {
    position: absolute;
    display: none;
    z-index: 50;
    border-collapse: collapse;
    font-size: .8em;
}
.popup td.corner {
    height: 13px;
    width: 15px;
}
.popup td#topleft { 
    background-image: url(bubble/bubble-1.png); 
} 
.popup td.top { 
    background-image: url(bubble/bubble-2.png); 
}
.popup td#topright { 
    background-image: url(bubble/bubble-3.png); 
}
.popup td.left { 
    background-image: url(bubble/bubble-4.png); 
}
.popup td.right { 
    background-image: url(bubble/bubble-5.png); 
}
.popup td#bottomleft { 
    background-image: url(bubble/bubble-6.png); 
}
.popup td.bottom { 
    background-image: url(bubble/bubble-7.png); 
    text-align: center;
}
.popup td.bottom img { 
    display: block; 
    margin: 0 auto; 
}
.popup td#bottomright { 
    background-image: url(bubble/bubble-8.png); 
}
Pulsar
+2  A: 

I found this one a while back. Looks good to me:

http://flowplayer.org/tools/demos/tooltip/custom-effect.html

Check out all of the demos.

tahdhaze09
+1  A: 

I have programmed an useful jQuery Plugin to create easily smart bubble popups with only a line of code in jQuery!

What You can do: - attach popups to any DOM element! - mouseover/mouseout events automatically managed! - set custom popups events! - create smart shadowed popups! (in IE too!) - choose popup’s style templates at runtime! - insert HTML messages inside popups! - set many options as: distances, velocity, delays, colors…

Popup’s shadows and colorized templates are fully supported by Internet Explorer 6+, Firefox, Opera 9+, Safari

You can download sources from http://plugins.jquery.com/project/jqBubblePopup

max
+25  A: 

Qtip is the best one I've seen. It's MIT licensed, beautiful, has all the configuration you need.

Koobz
By far the best. One line of code vs all the other huge solutions others have offered. I hope this response gets voted up.
Peter Walke
so simple...awesome answer
David
Qtip has compatibility problems with jQuery 1.4+. Simple one-line fix to qTip plug in fixes it though. See here: http://craigsworks.com/projects/forums/thread-solved-qtip-1-0-0rc3-does-not-work-with-latest-jquery-release
tchaymore
I looked at Qtip today and while it does work there are some down sides: hasn't been updated in a while, is missing or has not documented some obvious things (want to build tool tip text with a function that is called when the tip is displayed) and is a hefty download (partly because it appears to include a lot of stuff like rounded corner styling). Hopefully not seen as negative -- just trying to save someone else some time. Definitely worth considering but there are some downsides.
Cymen
A: 

I'm trying to make a "bubble" that can popup when the onmouseover event is fired and will stay open as long as the mouse is over the item that threw the onmouseover event OR if the mouse is moved into the bubble. My bubble will need to have all manners of html and styling including hyperlinks, images, etc.

All those events fully managed by this plugin...

http://plugins.jquery.com/project/jqBubblePopup

max
A: 

ColorTip is the most beautiful i've ever seen

tymonn
+1  A: 

For what it's worth, BeautyTips does a nice job as well.

Rio
+1  A: 

Although qTip (the accepted answer) is good, I started using it, and it lacked some features I needed.

I then stumbled upon PoshyTip - it is very flexible, and really easy to use. (And I could do what I needed)

Bozho
A: 

Use the new release 2.0 of jQuery Bubble Popup at

http://www.vegabit.com/jquery_bubble_popup_v2/

max