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="coordinates-checkbox">
  <input type="checkbox" id="display-coordinates" />
  <label for="display-coordinates">Display coordinates</label>
</div>

<div id="example" class="slide">
  <div class="slide__image-wrapper">
    <img class="slide__image" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/225363/forest.jpg" alt="Woods landscape">
  </div>
  <div class="slide__content">
    <h2 class="slide__headline">In The Wilderness</h2>
    <button class="slide__action btn">Book Travel</button>
  </div>
  <div class="coordinates-overlay"></div>
  <div id="coordinates" class="coordinates-tooltip"></div>
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Playfair+Display:700|IBM+Plex+Sans:500&display=swap');

:root {
  --color-primary: #56677E;
  --color-secondary: #101118;
  --base-duration: 500ms;
  --base-ease: cubic-bezier(0.25, 0.46, 0.45, 0.84);
}

// ================================================
// Transforms used for parallax effect
// Try changing the --d values within each rule-set
// and hover over the slide
// ================================================

.slide {
 --x: 0;
 --y: 0;
 --d: 50;
  
  &:hover .slide__image-wrapper {
    transform: 
      scale(1.025)
      translate(
        calc(var(--x) / var(--d) * 1px),
        calc(var(--y) / var(--d) * 1px)
      );
  }
}

.slide__image {
  --d: 20;

  transform: 
    translate(
      calc(var(--x) / var(--d) * 1px),
      calc(var(--y) / var(--d) * 1px)
    );
}

.slide__content {
  --d: 60;

  transform: 
    translate(
      calc(var(--x) / var(--d) * -1px),
      calc(var(--y) / var(--d) * -1px)
    );
}

// ========================
// Base
// ========================

*,
*:before,
*:after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  background-color: var(--color-secondary);
  font-family: 'IBM Plex Sans', sans-serif;
  overflow-x: hidden;
  padding: 4rem 2rem;
  width: 100%;
}

h1, h2, h3 {
  font-family: 'Playfair Display', serif;
}

// ========================
// Button
// ========================

.btn {
  background-color: var(--color-primary);
  border: none;
  border-radius: 0.125rem;
  color: white;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  padding: 1em 2em 1.125em;
  position: relative;
  z-index: 1;
  
  &:active {
    transform: translateY(1px);
  }
}

// ========================
// Slide
// ========================

.slide {  
  align-items: center;
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  text-align: center;
  width: 75vmin;
  z-index: 1;
  
  &:after {
    content: '';
    display: block;
    padding-bottom: 100%;
  }
}

// ========================
// Slide image wrapper
// ========================

.slide__image-wrapper {
  border-radius: 1%;
  height: 100%;
  left: 0%;
  overflow: hidden;
  position: absolute;
  top: 0%;  
  transition: transform calc(var(--base-duration) / 4) var(--base-ease);
  width: 100%;
}

// ========================
// Slide image
// ========================

.slide__image {
  --d: 20;
  
  height: 110%;
  left: -5%;
  object-fit: cover;
  pointer-events: none;
  position: absolute;
  top: -5%;
  transition: transform var(--base-duration) var(--base-ease);
  user-select: none;
  width: 110%;  
}

// ========================
// Slide headline
// ========================

.slide__headline {
  font-size: 8vmin;
  font-weight: 600;
  position: relative;
}

// ========================
// Slide content
// ========================

.slide__content {
  --d: 60;

  align-items: center;
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: center;
  left: 0;
  padding: 4vmin;
  position: absolute;
  top: 0;
  transition: transform var(--base-duration) var(--base-ease);
  width: 100%;
  z-index: 1;
  
  > * + * {
    margin-top: 2rem;
  }
}

// ========================
// Coordinates
// ========================

.display-coordinates {
  .coordinates-overlay,
  .slide:hover .coordinates-tooltip {
    display: block;
  }
}

.coordinates-checkbox {
  align-items: center;
  color: white;
  display: flex;
  position: fixed;
  top: 1rem;
  
  label {
    font-size: 0.9rem;
    margin-left: 0.25rem;
  }
}

.coordinates-tooltip {
  color: red;
  display: none;
  pointer-events: none;
  position: absolute;
  white-space: nowrap;
  z-index: 100;
  
  &::after {
    counter-reset: x var(--x) y var(--y);
    content: 'x: ' counter(x) ', y: ' counter(y);
  }  
}

.coordinates-overlay {
  background-color: rgba(black, 0.8);
  display: none;
  height: 100%;
  position: absolute;
  width: 100%;
  z-index: 100;
  
  &:before,
  &:after {
    background: rgba(white, 0.5);
    content: '';
    height: 1px;
    left: 50%;
    position: absolute;
    top: 50%;
    width: 100%;
  }
  
  &:before {
    transform: translate(-50%, -50%);
  }
  
  &:after {
    transform: translate(-50%, -50%) rotate(90deg);
  }
}
              
            
!

JS

              
                const slide = document.getElementById('example');
const tooltip = document.getElementById('coordinates');
const toggle = document.getElementById('display-coordinates');

slide.addEventListener('mousemove', function(e) {
  // Get dimensions of slide element
  const r = this.getBoundingClientRect()

  // Set x and y values prop values based on center of slide element
  this.style.setProperty('--x', e.clientX - (r.left + Math.floor(r.width / 2)))
  this.style.setProperty('--y', e.clientY - (r.top + Math.floor(r.height / 2)))
})

slide.addEventListener('mouseleave', function() {
  // Reset x and y prop values when no longer hovering
  this.style.setProperty('--x', 0)
  this.style.setProperty('--y', 0) 
})


document.body.addEventListener('mousemove', function(e) {
  // Have coordinate values follow the user's cursor
  tooltip.style.left = e.pageX - 15 + 'px';
  tooltip.style.top = e.pageY - 70 + 'px';
})

toggle.addEventListener('change', function(e) {
  // Toggle the display of coordinate values
  this.checked
    ? document.body.classList.add('display-coordinates')
    : document.body.classList.remove('display-coordinates')           
})

              
            
!
999px

Console