Pen Settings



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


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.


                <img id="img" src="" />

<div id="info">Move your mouse around...</div>


                body {
  overflow: hidden;

#info {
  position: fixed;
  padding: 10px;
  left: 0;
  top: 0;
  color: #333;
  user-select: none;
  font-weight: bold;
    -1px -1px 0 rgba(255,255,255,0.5),
    1px -1px 0 rgba(255,255,255,0.5),
    -1px 1px 0 rgba(255,255,255,0.5),
    1px 1px 0 rgba(255,255,255,0.5);


                // Acceleration value between 0 and 1
// Smaller values result in a slower/smoother looking animation
let acceleration = 0.05;

let img = {
  element: document.querySelector("#img"),
  maxX: 0,
  maxY: 0,
  x: 0,
  y: 0

let mouse = { x: 0, y: 0 };

let vw = 0;
let vh = 0;

let setX = gsap.quickSetter(img.element, "x", "px");
let setY = gsap.quickSetter(img.element, "y", "px");
let mapX, mapY;

function init() {
  // Sets viewport dimensions and img x/y limits
  window.addEventListener("mousemove", onMove);
  window.addEventListener("resize", resize);  

function update() {
  // adjust speed for higher refresh monitors
  const dt = 1.0 - Math.pow(1.0 - acceleration, gsap.ticker.deltaRatio()); 
  let x = mapX(mouse.x);
  let y = mapY(mouse.y);
  img.x += (x - img.x) * dt;
  img.y += (y - img.y) * dt;

function resize() {
  vw = window.innerWidth;
  vh = window.innerHeight;
  img.maxX = vw - img.element.naturalWidth;
  img.maxY = vh - img.element.naturalHeight;
  mapX = gsap.utils.mapRange(0, vw, 0, img.maxX);
  mapY = gsap.utils.mapRange(0, vh, 0, img.maxY);

function onMove(event) {
  mouse.x = event.clientX;
  mouse.y = event.clientY;

// Initialize app once image has loaded
window.addEventListener("load", init);