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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <h1>Flourish popup</h1>
<p>Mouse over the box below. The popup bubble should always remain within the box, and the arrow be pointing in one of the eight compass directions.</p>
<div class="test" id="test1"></div>

<p>This tests the behaviour when there is a lot of text in the popup. When the mouse is near the middle of the box, the bubble cannot be accommodated completely within it. The arrow should again always point in one of the eight compass directions, and the bubble should never overlap the box horizontally, only vertically.</p>
<div class="test" id="test2"></div>

<p>This tests the behaviour when there is so much text in the popup that it cannot be accommodated within the container at all. In this case the box should protrude outside the box vertically but not horizontally, and the arrow should slide along the edges of the box to fit it in as well as possible.</p>
<div class="test" id="test3"></div>

<p>This is the same as the previous test, except that the box should protrude horizontally but not vertically.</p>
<div class="test" id="test4"></div>

<p>This popup box should always point upwards.</p>
<div class="test" id="test5"></div>

<p>This popup box should always point to the right.</p>
<div class="test" id="test6"></div>

<p>This popup box should always point down.</p>
<div class="test" id="test7"></div>

<p>This popup box should always point left.</p>
<div class="test" id="test8"></div>

<p>This popup box should point right or left.</p>
<div class="test" id="test9"></div>

<p>This popup should point within the smaller box.</p>
<div class="test" id="test10">
        <div class="inner"></div>
</div>

<p>This popup should have a black background and white text.</p>
<div class="test" id="test11"></div>

<p>This popup should be translucent.</p>
<div class="test" id="test12"></div>

              
            
!

CSS

              
                body { width: 800px; margin: auto; font-family: sans-serif; }

.test { height: 300px; width: 600px; border: 1px solid red; margin: 24px; cursor: crosshair; }
.flourish-popup { pointer-events: none; }

#test10 { position: relative; }
#test10 .inner { position: absolute; left: 50px; right: 50px; top: 50px; bottom: 50px; background: #ccc; }

#flourish-popup-11 .flourish-popup-svg g { fill: rgba(0,0,0,0.9); }
#flourish-popup-11 .flourish-popup-content { color: white; }

#flourish-popup-12 .flourish-popup-svg g { opacity: 0.6; }

              
            
!

JS

              
                function test(id, text_template, callback) {
  var el = document.getElementById(id);
  if (!el) return console.error("Element not found: #" + id);

  var popup = Popup().container(el);
  if (callback) callback(popup);

  el.onmousemove = function(e) {
    var x = e.clientX, y = e.clientY;
    popup.point(x, y).html(text_template(x, y)).draw();
  };
  el.onmouseout = function(e) {
    popup.hide();
  };
}

function muchText(n) {
  var much_text = "";
  for (var i = 0; i < n; i++) {
    much_text += "This is some additional text to fill up the bubble. ";
  }

  return function(x, y) {
    return "Mouse at (" + x + "," + y + "). " + much_text;
  };
}


var much0 = muchText(0), much4 = muchText(4),
    much8 = muchText(8), much15 = muchText(15);

test("test1", much0);

test("test2", much8, function(popup) {
  popup.maxWidth("60%");
});

test("test3", much15);

test("test4", much15, function(popup) {
  popup.fallbackFit("vertical");
});

test("test5", much15, function(popup) {
  popup.directions(["bottomFlexible"]);
});

test("test6", much15, function(popup) {
  popup.directions(["leftFlexible"]);
});

test("test7", much15, function(popup) {
  popup.directions(["topFlexible"]);
});

test("test8", much15, function(popup) {
  popup.directions(["rightFlexible"]);
});

test("test9", much15, function(popup) {
  popup.directions(["leftFlexible", "rightFlexible"]);
});

test("test10", much8, function(popup) {
  popup.container(
    document.querySelector("#test10 .inner")
  );
});

test("test11", much4);

test("test12", much4, function(popup) {
  popup.directions(["right"]);
});

              
            
!
999px

Console