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

              
                    <body>

        <div class="description">

            <p>Here is a demo of an image being revelaed by moving the cursor over the window.</p>

        </div> 

        <div class="container" id="imageExampleContainer" onmousemove="revealImage(); return false;">

            <div class="imageViewerContainer" id="imageViewer" ></div>

        </div>

   <body>
              
            
!

CSS

              
                .description{
    margin: 2% auto 2% auto;  
}

.description p{
    font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
    font-size: 1.2em;
    text-align: center;
}

.container{
    width: 70vw;
    height: 80vh;

    touch-action: pan-x pan-y pinch-zoom;
  
    border: 1px solid black;

    margin: 2vh auto;

}

.imageViewerContainer{
    position: relative;  
}

.clipContainer{
    width: 50vw;
    height: 25vh;

    margin: 2% auto 2% auto;
}

.clipContainer iframe{
    margin-left: 14%;

    width: 1280px;
    height: 720px;
}

.emptySpace{
    width: 50%;
    height: 200vh;
}

.showSmallClipViewer{
    position: fixed;
    right: 0;
    bottom: 0;    
    width: 320px;
    height: 240px;
  
    border: 1px solid red;
}

.showSmallClipViewer iframe{
    width: 320px;
    height: 240px;

    margin: 0 auto;
}

              
            
!

JS

              
                var xPos, yPos, xCord, yCord;

var grid, rect, client_X, client_Y; 

var imageReveal;

var windowScrollTop, bottomOfWindow, elemTop, elemBottom;

function displayViewer(){
/* Displays a small window for the image in the reveal image demo */
  
  imageReveal.style.display = "block";    
  grid.style.cursor = "none";
}

function getValues(){
 /* Gets the values for the selected process varibles */

  grid = document.getElementById("imageExampleContainer");           
            
  rect = grid.getBoundingClientRect();

  imageReveal = document.getElementById("imageViewer");
                     
  imageReveal.style.left = xPos + "px";
  imageReveal.style.top = yPos + "px";
  imageReveal.style.width = "15%";
  imageReveal.style.height = "15%";    
}

function getPositionValues(){   
/* Get the position of the cursor */

    xPos =  event.clientX - rect.left;
    yPos = event.clientY - rect.top;

}

function revealImage(){
/* Shows a small part of the image specified in the url */

    var callingID = 1;

    getValues(callingID);

    getPositionValues();  
 
    client_X = event.clientX;
    client_Y = event.clientY;    
  
    /* + 5 adds a small buffer */
  
    if(client_X >= rect.left && client_X <= (rect.right + 5) - (imageReveal.offsetWidth)){ 
      if(client_Y >= rect.top && client_Y <= (rect.bottom + 5) - (imageReveal.offsetHeight)){
                
            displayViewer(callingID);        
                                    
             xCord = xPos;
             yCord = yPos;
  
             imageReveal.style.backgroundImage = "url('https://wallpaperaccess.com/full/2068577.jpg')";
             imageReveal.style.backgroundPosition
             imageReveal.style.backgroundPosition = "-" + xCord + "px " + "-" + yCord + "px";
             imageReveal.style.transform = "scale(1)";   
             imageReveal.style.border = "1px solid red";             
                              
        }
        else{
            reset(callingID);
        }

    }    
    else{
        reset(callingID);
    }

}

function reset(){  
/* Stops moving the image in the reveal image demo.*/
 
    imageReveal.style = "none";
    grid.style.cursor = "default";       

}

              
            
!
999px

Console