Pen Settings

HTML

CSS

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

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.

HTML

              
                mixin box(content)
  .grid__item
    .box
      img.box__image(src= content.img alt='')
      h2.box__title= content.title
      h3.box__subtitle= content.subtitle
      p.box__description= content.description
      
main
  .grid
    +box({
      title: 'Example Title',
      subtitle: 'Subtitle',
      img: 'https://tinyurl.com/ybxmkoew',
      description: 'Cillum et in nulla commodo. Ex sunt anim ut et voluptate sunt irure proident. Velit elit velit dolore amet deserunt enim dolore est sint esse.'
    })
    +box({
      title: 'Different Title',
      subtitle: 'Subtitle Two',
      img: 'https://tinyurl.com/yb4s3v86',
      description: 'Ex sunt anim ut et voluptate sunt irure proident. Velit elit velit dolore amet deserunt enim dolore est sint esse.'
    })
              
            
!

CSS

              
                // BOX-SIZING - FONT-SIZING PRESETS
html {
  box-sizing: border-box;
  font-size: 62.5%; // Scales 1 rem unit to 10px
}

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

body {
  width: 100%;
  max-width: 100vw;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: #fff;
  font-size: 1.6rem; // = 16px default font size
  background-image: linear-gradient(-180deg, #262628 0%, #18181a 100%);
  padding: 10vw 5vw;
}

.close {
  position: absolute;
  right: 32px;
  top: 32px;
  width: 30px;
  height: 30px;
  opacity: 0.3;
  padding: 0;
  background-color: transparent;
  border: none;
  transition: opacity 250ms;
  display: flex;
  align-items: center;
  justify-content: center;
  
  &:hover {
    opacity: 1;
  }
  
  &::before,
  &::after {
    position: absolute;
    content: ' ';
    height: 4px;
    width: 30px;
    background-color: #FFF;
    margin: auto;
  }
  
  &::before {
    transform: rotate(45deg);
  }
  &::after {
    transform: rotate(-45deg);
  }
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-flow: row;
  grid-gap: 5vw;
  max-width: 800px;
  margin: 0 auto;
}

.grid__item {
  // use if needed
}

.box {
  height: 100%;
  position: relative;
  cursor: pointer;
}

.box__image {
  margin: 0 auto;
  display: block;
  width: 100%;
  background-color: rgba(white, 0.1);
  height: 250px;
  object-fit: cover;
  transform-origin: center;
}

.box__description {
  display: none;
}

.details {
  position: fixed;
	width: 100%;
	height: 100%;
	bottom: 0;
	left: 0;
  right: 0;
  top: 0;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	pointer-events: none;
  visibility: hidden;
  pointer-events: none;
  
  &--open {
    pointer-events: auto;
    visibility: visible;
  }
}

.details__inner {
  margin: auto;
  max-width: 800px;
}

.details__image {
  height: 300px;
  object-fit: cover;
  width: 300px;
  transform-origin: center;
  filter: grayscale(1);
  visibility: visible !important;
  opacity: 1 !important;
}

.scrim {
  background-color: rgba(0,0,0,0.8);
  position: absolute;
  bottom: 0;
	left: 0;
  right: 0;
  top: 0;
  z-index: -1;
  opacity: 0;
  visibility: hidden;
}

.details__inner,
.grid__item {
  outline: 1px solid red;
}
              
            
!

JS

              
                console.clear();
var log = console.log;

class Details {
  constructor() {
    
    this.timeline = new TimelineMax().timeScale(0.25);
    
    
    
    // Details Modal Template
    const template = `
      <div class="scrim"></div>
      <button class="close"></button>
      <div class="details__inner">
        <image class="image details__image" src="" alt=""/>
        <h2 class="content details__title"></h2>
        <h3 class="content details__subtitle"></h3>
        <p class="content details__description"></p>
      </div>
    `;
    
    this.details = document.createElement('div');
    this.details.className = 'details';
    this.details.innerHTML = template;
    content.appendChild(this.details);
    
    this.init();
  }
  
  init() {
    this.scrim = this.details.querySelector('.scrim');
    this.closeBtn = this.details.querySelector('.close');
    this.image = this.details.querySelector('.details__image');
    this.title = this.details.querySelector('.details__title');
    this.subtitle = this.details.querySelector('.details__subtitle');
    this.description = this.details.querySelector('.details__description');
    
    this.initEvents();
  }
  
  initEvents() {
    // Events (close)
    this.scrim.addEventListener('click', () => {
      this.close();
    });
    // or     
    this.closeBtn.addEventListener('click', () => {
      this.close();
    });
  }
  
  fill(info) {
    // Fill template in with Item Data     
    this.image.src = info.image;
    this.title.innerHTML = info.title;
    this.subtitle.innerHTML = info.subtitle;
    this.description.innerHTML = info.description;
  }
  
  close() {
    
    // prevent animation from being interrupted
    if (this.timeline.isActive()) { return; }
    
    // Close Details Modal     
    const a = this.currentItem.image.getBoundingClientRect(); // box image
    const b = this.image.getBoundingClientRect(); // details image
    
    // const tl = new TimelineMax()
    
    this.timeline.clear()
      .to([this.scrim, this.content], 0.2, {
        autoAlpha: 0
      })
      .to(this.image, 0.3, {
        x: -(b.left - a.left),
        y: -(b.top - a.top),
        width: a.width,
        height: a.height,
        ease: Sine.easeOut
      }, 0)
      .set(this.image, {
        autoAlpha: 0
      })
      .set(this.currentItem.image, {
        autoAlpha: 1
      })
      .add(() => {
        this.currentItem = null;
        this.details.classList.remove('details--open');
      });    
  }
  
  open(item) {
    // Open Details Modal     
    if (this.currentItem) { return; }
    this.currentItem = item;
    
    this.image.style.cssText = ""; // reset styles
    
    const a = item.image.getBoundingClientRect(); // box image
    const b = this.image.getBoundingClientRect(); // details image
    
    const offset = [5, 10, 20];
    
    // Modal copy
    this.content = [this.title, this.subtitle, this.description];
    
    
    // const tl = new TimelineMax()
    
    this.timeline.clear()
      .set(this.content, {
        y: i => offset[i]
      })
      // .set([item.image, this.content], {
      .set([this.content], {
        autoAlpha: 0
      })
      .set(this.image, {
        x: -(b.left - a.left),
        y: -(b.top - a.top),
        width: a.width,
        height: a.height
      })
      .to(this.scrim, 0.2, {
        autoAlpha: 1
      }, 0)
      .to(this.image, 0.3, {
        x: 0,
        y: 0,
        width: b.width,
        height: b.height,
        ease: Sine.easeOut
      }, 0)
      .staggerTo(this.content, 0.2, {
        autoAlpha: 1,
        y: 0
      }, 0.01, 0.2);

    this.details.classList.add('details--open');    
  }
}



class Item {
  constructor(el) {
    this.el = el; 
    this.box = el.querySelector('.box');
    this.boxImage = el.querySelector('.box__image');
    
    // Get Item Content     
    this.info = {
      image: this.boxImage.src,
      title: this.box.querySelector('.box__title').innerHTML,
      subtitle: this.box.querySelector('.box__subtitle').innerHTML,
      description: this.box.querySelector('.box__description').innerHTML
    }
    
    this.initEvents();
  }
  
  initEvents() {
    // Events (open)
    this.box.addEventListener('click', () => {
      this.open()
    });
  }
  
  open() {
    // Populate Details Data    
    details.fill(this.info);
    
    // Open Details     
    details.open({        
      image: this.boxImage // provide box image data
    });
  }
}

const DOM = {};
const grid = document.querySelector('.grid');
const content = grid.parentNode;
const gridItems = Array.from(grid.querySelectorAll('.grid__item'));
let items = [];
gridItems.forEach(item => items.push(new Item(item)));

const details = new Details();
              
            
!
999px

Console