Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ add another resource


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


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.


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.


    <div id="board">
        <div id="box"></div>            
        <div id="area"></div>
        <div id="point">
            <div id="marker">1</div>

                <td><span id="drag-x"></span></td>
                <td><span id="drag-y"></span></td>
                <td>Point 1</td>
                <td><span id="point-x"></span></td>
                <td><span id="point-y"></span></td>
                <td><span id="inside"></span></td>
                <td><span id="hitting"></span></td>                

    <p>Move the box and point around to perform a hit test.</p>



                body {
    padding: 50px;
    position: relative;

* {
    box-sizing: border-box;

main {
    opacity: 0;
    visibility: hidden;

p {
    font-size: 14px;
    color: #444;
    font-style: italic;

table {    
    font-size: 14px;
    margin: 25px 0;
    td, th {
        text-align: left;
        border: 1px solid #aaa;
        padding: 4px 8px;

#board {
    height: 500px;
    width: 700px;    
    position: relative;    
    border: 1px solid #aaa;

#box {    
    top: -1px;
    left: -1px;    
    height: 100px;
    width: 100px;    
    position: absolute;    
    background: cornflowerBlue;
    border: 1px solid navy;
    z-index: 10;
    &.hit {
        background: seagreen;
        background: greenyellow;
        border-color: green;

#point {
    position: absolute;
    z-index: 30;
    #marker {        
        text-align: center;
        color: white;
        font-size: 10px;
        line-height: 16px;        
        height: 16px;
        width: 16px;
        border-radius: 50%;
        background: red;
        position: absolute;
        top: -8px;
        left: -8px;        
        border: 1px solid rgba(0,0,0,0.5);    
    &.hit #marker {
        background: green;

#area {    
    top: 0;
    left: 0;  
    right: -1px;
    bottom: -1px;
    position: absolute;
    pointer-events: none;
    background: rgba(255,0,0,0.2);
    border: 1px solid red;
    z-index: 20;
    &.hit {
        background: rgba(0,255,0,0.2);
        border-color: green;



var board  = $("#board");
var box    = $("#box")[0];
var point  = $("#point")[0];
var area   = $("#area")[0];
var offset = board[0].getBoundingClientRect();

var table = {
    hitting : $("#hitting"),
    inside  : $("#inside"),
    dragX   : $("#drag-x"),
    dragY   : $("#drag-y"),
    pointX  : $("#point-x"),
    pointY  : $("#point-y")

// Set gsTranform object on elements
TweenLite.set(box, { x: 0, y: 0 });
TweenLite.set(point, { x: 350, y: 250 });

// Getter for gsTransform 
var position = {
    get dragX()  { return Math.floor(box._gsTransform.x); },
    get dragY()  { return Math.floor(box._gsTransform.y); },    
    get pointX() { return Math.floor(point._gsTransform.x); },
    get pointY() { return Math.floor(point._gsTransform.y); }    

Draggable.create(box, {
    bounds: board,
    onDrag: hitTest,
    onThrowUpdate: hitTest,
    overshootTolerance: 0,
    throwProps: true,
    zIndexBoost: false

Draggable.create(point, {
    bounds: board,
    onDrag: resizeArea,
    onThrowUpdate: resizeArea,
    overshootTolerance: 0,
    throwProps: true,
    zIndexBoost: false

function resizeArea() {            
    TweenLite.set(area, { left: position.pointX, top: position.pointY });    

function hitTest() {
    // Adjust for offset
    var x = position.pointX + offset.left;
    var y = position.pointY +;
    var hitting = Draggable.hitTest(box, { pageX: x, pageY: y });
    var inside  = Draggable.hitTest(box, { left: x, top: y });
    // Add .hit class if true
    area.className  = inside  ? "hit" : "";
    box.className   = hitting ? "hit" : "";
    point.className = hitting ? "hit" : "";
    // Update table

// Init
TweenLite.set("main", { autoAlpha: 1 });