Pen Settings

HTML

CSS

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

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

Auto Save

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

              
                <div class="container display">
    <p>
        Page X: <span class="pageX">0</span>
        <br>
        Page Y: <span class="pageY">0</span>        
    </p>
    <p>
        Client X: <span class="clientX">0</span>
        <br>
        Client Y: <span class="clientY">0</span>        
    </p>
    <p>
        Offset X: <span class="offsetX">0</span>
        <br>
        Offset Y: <span class="offsetY">0</span>        
    </p>
</div>


<div class="container empty">
    <h3>I'm empty, roll over the bellow containers.</h3>
</div>


<div class="container parent1">
    <div class="follower">
        <p>0</p>
    </div>
</div>

<div class="container parent2">
    <div class="follower">
        <p>0</p>
    </div>
</div>


              
            
!

CSS

              
                /* **************************************** */
/* Default CSS styles being imported from:
/* https://codepen.io/dipscom/pen/RWXPBB
/* **************************************** */


/* ****************** */
/* Notes and reminders
/* ****************** */



/* ****************** */
/* Local CSS styling
/* ****************** */
.container {
    height: 40vh;
    position: relative;
    overflow: hidden;
}

.container.display {
    position: fixed;
    width: 20ch;
    min-width: auto;
    min-height: auto;
    height: auto;
    left: 0;
    top: 0;
    margin: 0;
    z-index: 1;
}

.follower {
    width: 5rem;
    height: 5rem;
    border-radius: 100%;
    display: flex;
    overflow: hidden;
    background: hsl(0, 0%, 98%);
    position: absolute;
    left: 0;
    top: 0;
    pointer-events: none; /* Very important to prevent the follower from messing up with the mouse move */
}

.follower > * {
    margin: auto;
}

h3 {
    text-align: center;
}
              
            
!

JS

              
                var parent1 = document.querySelector('.parent1')
var parent2 = document.querySelector('.parent2')
var displays


function onMouseMove( e ) {
    
    // this refers to the caller
    console.log(this)
    
    // Find its child
   var follower = this.querySelector('.follower')
    
    TweenMax.to(follower, 0.3, {
        x: e.offsetX,
        y: e.offsetY,
        ease:Power4.easeOut
    })
    
    displays.pX.textContent = e.pageX
    displays.pY.textContent = e.pageY
    
    displays.cX.textContent = e.clientX
    displays.cY.textContent = e.clientY
    
    displays.oX.textContent = e.offsetX
    displays.oY.textContent = e.offsetY
    

}


function onMouseLeave( e ) {
    const rect = this.getBoundingClientRect()
    const center = {
        w: Math.round(rect.width * 0.5),
        h: Math.round(rect.height * 0.5)
    }
    const trg = this.querySelector('.follower')
    
    TweenMax.to( trg, 1, {
        x: center.w,
        y: center.h,
        ease: Back.easeInOut
    } )
}


function init() {

    // Listen for mouse movement when over either one of the parents
    parent1.addEventListener('mousemove', onMouseMove)
    parent2.addEventListener('mousemove', onMouseMove)

    parent1.addEventListener('mouseleave', onMouseLeave)
    parent2.addEventListener('mouseleave', onMouseLeave)

};


// wait until DOM is ready
document.addEventListener("DOMContentLoaded", function(event) {
    
    // wait until window, stylesheets, images, links, and other media assets are loaded
    window.onload = function() {
        
        displays = {
            pX: document.querySelector('.pageX'),
            pY: document.querySelector('.pageY'),

            cX: document.querySelector('.clientX'),
            cY: document.querySelector('.clientY'),

            oX: document.querySelector('.offsetX'),
            oY: document.querySelector('.offsetY'),
        }
                
        // Center the pivot point of the follower
        TweenMax.set('.follower', {
            xPercent: -50,
            yPercent: -50
        })

        // All ready, start!
        init();

     };

});



              
            
!
999px

Console