Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <div id="intro">
<h1>Giphy ToolTip</h1>
  <p>To test this out, try hovering over the purple word. For a better experience, hover over the purple word more than once.</p>
  <p>Want to test it out on <u>other words</u>? Use the input below (the input in the black box) under "Change Parameter" to insert your own word.</p>
</div>
<div id="cont">
  <p>There was once a <span class="tooltip">princess</span> from a very far away land.</p>
  <div id="query">
    <label for="textbox">Change Parameter</label><input id="textbox" type="text" placeholder="e.g. paper, cheese, dog"/>
  </div>
</div>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Roboto);
$tooltip-color: lighten(mix(blue, yellow, 70%), 10%);
*{
  outline: 0!important
}
#intro{
  position: absolute;
  top: 1.5em;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  p{
    max-width: 50%;
    margin: auto;
    margin-bottom: 1em;
  }
}
#query{
  background: #000;
  color: #fff;
  margin: 1em -1.5em -1.5em;
  padding: 0.75em 1.5em 1.5em;
  box-sizing: border-box;
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 4px;
  position: absolute;
  width: 100%;
  input{
    padding: 0.5em 1em;
    margin-top: 0.5em;
    width: 100%;
    box-sizing: border-box;
    &:focus{
      border: 1px solid mix(white, crimson, 75%);
    } 
  }
}
html, body{
  font-family: 'Roboto', sans-serif;
  height: 100%;
  width: 100%;
  padding: 0;
  margin: 0;
  background: mix(white, red, 85%);
}
#cont{
  width: 250px;
  line-height: 1.5em;
  padding: 1.5em;
  border: 1px solid #cecece;
  border-radius: 4px;
  position: relative;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  background: #FFF;
}
.tooltip{
  text-decoration: none;
  color: $tooltip-color;
  font-weight: bold;
  display: inline-block;
  padding: 10px 5px;
  &:hover{
    background: mix(white, red, 85%);
  }
}
#tooltip{
  background: #000;
  text-align: center;
  color: #FFF;
  position: absolute;
  left: 0;
  padding: 10px;
  &:after{
    content: ' ';
    display: block;
    position: absolute;
    bottom: -10px;
    left: 50%;
    margin-left: -15px;
    border-right: 10px solid transparent;
    border-top: 15px solid black;
    border-left: 10px solid transparent;
  }
  img{
    margin: auto;
  }
}
              
            
!

JS

              
                var aList = document.querySelectorAll('.tooltip');
var tooltip = {
  randomGif: function(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  },
  fadeIn: function(el){
    if(Number(el.style.opacity)<1){
      el.style.opacity = Number(el.style.opacity) + 0.2;
      el.style.top = (Number(el.style.top.replace('px','')) - 2) + 'px';
      setTimeout(function(){
        return tooltip.fadeIn(el);
      }, 30);
    }
  },
  init: function(el, elX, elY){
    var $el = el, x = elX, y = elY;
    $.ajax({
      url: 'http://api.giphy.com/v1/gifs/search?q='+ el.innerHTML.replace(/ /g, '+') +'&api_key=dc6zaTOxFJmzC',
      dataType: 'json',
      success: function(gifs){
        var gif = gifs.data[tooltip.randomGif(0,gifs.data.length)].images.fixed_height;
        var gifUrl = gif.url;
        var width = Number(gif.width);
        var height = Number(gif.height);
        tooltip.create(gifUrl, $el, height, width, elX, elY);
      }
    }).done(function(){
      tooltip.fadeIn(document.getElementById('tooltip'));
    });
  },
  create: function(el, par, elH, elW, elX, elY){
    var tip = document.createElement('div');
    var tipImg = document.createElement('img');
    tipImg.src = el;
    tipImg.style.width = elW/2 + 'px';
    tip.id = 'tooltip';
    tip.style.opacity = 0;
    tip.style.top =  (par.offsetParent.offsetTop - (elH/2) - Number(getComputedStyle(par.offsetParent).height.replace('px',''))) + 40 + 'px';
    tip.style.left =  (par.offsetParent.offsetLeft-((elW/4)-(Number(getComputedStyle(par).width.replace('px',''))/2))+5) + 'px';
    tip.appendChild(tipImg);
    document.body.appendChild(tip);
  },
  remove: function(el){
    document.body.removeChild(document.getElementById('tooltip'));
  }
}
for(var i = 0; i<aList.length; i++){
  document.querySelectorAll('.tooltip')[i].addEventListener('mouseenter',function(e){
    tooltip.init(e.target, e.clientX, e.clientY);
  });
    document.querySelectorAll('.tooltip')[i].addEventListener('mouseleave',function(e){
    tooltip.remove(e.target);
  });
  document.getElementById('textbox').addEventListener('keyup', function(){
    document.querySelector('.tooltip').innerHTML = document.getElementById('textbox').value;
   
  });
}
              
            
!
999px

Console