cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div id="speechbubble"></div>

<div class="wrapper">
  <h1 class="hastip" data-moretext="This is the h1 tag over here">Simple JQuery Speech Bubble for tooltips</h1>
  <h2>No tooltip here!</h2>
  <p>This tooltip example changes arrow sides based on half screen width, it does not do up and down arrows, though they could be added in different cases.</p>
  <p class="hastip" data-moretext="This is another paragraph later in the page that can also have a hover tip on it.">Show it again here if the paragraph requires hover info. It could be added to any element. When it reaches the right side of the screen the class for the triangle before/after is toggled.</p>
  <a href="#" class="hastip" data-moretext="if a link">LINK</a>
</div>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Roboto:300);
h1,h2,h3,h4,h5,h6 {
  font-weight: normal;
  margin: 0.4em 0;
}

h1 {
  font-size: 48px;
}

h2 {
  font-size: 24px;
}

p {
  margin: 1em 0;
  line-height: 1.5em;
  font-weight: 600;
}

body,input,textarea,th,td {
  font-family: 'Roboto', sans-serif;
  font-size: 16px;
}

body {
  background: #aab5aa;
  color: #000;
}

a {
  color: #0581ba;
}

a:hover,
a:active,
a:focus {
  color: #07a6f0;
}

.wrapper {
  width: 80%;
  margin: auto;
}


/*--SPECIFIC--*/

#speechbubble {
  background: rgba(255, 255, 255, 0.8);
  width: 150px;
  padding: 10px;
  box-sizing: border-box;
  position: absolute;
  display: none;
}

#speechbubble.arrowleft:before {
  /*cannot access before and after with jquery, need to use a class to add or remove*/
  content: "";
  position: absolute;
  left: -10px;
  top: 10px;
  /*calc(50% - 5px) if want it to be centered vertically - 5px is half its height of 10*/
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-right: 10px solid rgba(255, 255, 255, 0.8);
  border-bottom: 5px solid transparent;
}

#speechbubble.arrowright:after {
  content: "";
  position: absolute;
  right: -10px;
  top: 10px;
  /*calc(50% - 5px) - as above*/
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-left: 10px solid rgba(255, 255, 255, 0.8);
  border-bottom: 5px solid transparent;
}
            
          
!
            
              $(document).ready(function() {

  $speech = $('#speechbubble');
  var tipContent;

  function moving() {
    $('.hastip').mousemove(function(e) {
      $speech.html(tipContent);
      $offset = 20; /*distance from mouse*/
      $speech.css("top", e.pageY);

      if (e.pageX <= ($(window).width() / 2)) {
        $speech.css("left", e.pageX + $offset);
        $speech.addClass('arrowleft');
        $speech.removeClass('arrowright');

      } else {
        $speech.css("left", (e.pageX - $speech.width() - ($offset * 2)));
        $speech.removeClass('arrowleft');
        $speech.addClass('arrowright');
      }
    });
  }

  $('.hastip').hover(showTip, hideTip);

  function showTip() {
    $speech.show();
    moving();
    tipContent = $(this).data('moretext');
  }

  function hideTip() {
    $speech.hide();
  }

});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console