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

              
                .product.wrapper
  .product__thumbnails.zooma-thumbnail
  .product__focus.zooma-main
    img(src="//picsum.photos/1000")
    img(src="//picsum.photos/1050")
    img(src="//picsum.photos/1100")
    img(src="//picsum.photos/1200")
    img(src="//picsum.photos/1250")
  .product__description
    h1 zooma
    h2 $0.00
    p This currently only works with square images.
              
            
!

CSS

              
                .zooma-main {
  overflow: hidden;
  position: relative;
  max-width: 500px;
  max-height: 500px;
  img {
    pointer-events: none;
    display: block;
    width: 100%;
    height: auto;
    cursor: zoom-in;
    opacity: 0;
    top: 0;
    left: 0;
    &.is-loaded {
      position: absolute;
    }
    &.is-active {
      opacity: 1;
      pointer-events: initial;
    }
    &.is-zoomed-in {
      cursor: zoom-out;
      width: initial;
    }
  }
}

.zooma-thumbnail {
  img {
    display: block;
    width: 80px;
    height: auto;
    opacity: 0.5;
    padding: 10px;
    &.is-active {
      opacity: 1;
      outline: 1px solid;
    }
  }
}

////////////////////////////////////////////////////////////

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

.wrapper {
  width: 1200px;
  margin: 0 auto;
}

.product {
  display: flex;
  flex-flow: row;
  justify-content: space-between;
  align-items: center;
  
  &__thumbnails {
    flex-shrink: 0;
  }
  
  &__focus {
    margin: 0 40px;
  }
  
  &__description {
    width: 30%;
  }
}
              
            
!

JS

              
                $(document).ready(function() {
  // Store initial image size
  function setImageSize() {
    var imageSize = Math.floor($('.zooma-main img:first-child').height());    
    if(imageSize <= 0) {
      requestAnimationFrame(setImageSize);
    }
    else {
      $('.zooma-main').css({width: imageSize, height: imageSize });
      $('.zooma-main img').addClass('is-loaded');
    }
  }
  
  requestAnimationFrame(setImageSize);
  
  
  
  // Populate thumbnails
  $('.zooma-main').children().clone().appendTo('.zooma-thumbnail');
    
  // Set state for first image
  $('.product img:first-child').addClass('is-active');
  
  // Thumbnail hover event listener
  $('.zooma-thumbnail img').on('mouseenter', function() {
    $('.product img').removeClass('is-active is-zoomed-in').prop('style', '').off('mousemove');
    $('.product img:nth-child(' + ($(this).index()+1) + ')').addClass('is-active');   
  });
  
  // Main image click to zoom event listener
  $('.zooma-main img').on('click', function(e) {
    // Toggle zoom-out cursor and unset max-width
    $(this).toggleClass('is-zoomed-in');
    
    // Zoom in
    if ($(this).hasClass('is-zoomed-in')) {
      // Variables for calculating relative position
      var scale = e.target.naturalWidth / $(e.target).parent().width();
      var max = -(1 - 1/scale);
      
      // Adjust mouse scale to the full-size image, then redraw
      e.offsetX *= scale;
      e.offsetY *= scale;
      calculateZoom(e);
      
      // Mouse event listener
      $(this).on('mousemove', calculateZoom);
      
      function calculateZoom(e) {       
        var x = e.offsetX * max + 'px';
        var y = e.offsetY * max + 'px';
        $(e.target).css({left: x, top: y});
      }
    }
    // Zoom out
    else {
      $(this).off('mousemove').prop('style', '');
    }
  });
});
              
            
!
999px

Console