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

              
                <main>
  <div class="grid">
    <div class="grid__item"></div>
    <div class="grid__item"></div>
    <div class="grid__item"></div>
  </div>
  <div class="details"></div>
</main>
              
            
!

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: 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;
  z-index: 2;
  
  &: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: 5em;
  max-width: 800px;
  margin: 0 auto;
}

.grid__item {
  // use if needed
}

.box {
  height: 100%;
  position: relative;
  cursor: pointer;
  padding-top: 10em;
}

.box__bg {
  height: 20em;
  background-color: rgba(#FFF, 0.2);
  position: relative;
}

.box__img {
  max-height: 25em;
  margin: 0 auto;
  display: block;
  position: absolute;
  top: 0;
  left: 50%;
  pointer-events: none;
  background-color: red;
  height: 100%;
  width: 50%;
  transform: translate3d(-50%, 0, 0);
  object-fit: cover;
}

.box__description {
  display: none;
}

.details {
  position: fixed;
	width: 100%;
	height: 100%;
	bottom: 0;
	left: 0;
  right: 0;
  top: 0;
	// z-index: 1000;
  z-index: 0;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	pointer-events: none;
  // opacity: 0;
  visibility: hidden;
  pointer-events: none;
  // background-color: rgba(0,0,0,0.8);
  
  &--open {
    pointer-events: auto;
    // opacity: 1;
    visibility: visible;
  }
}

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

.details__img {
  max-height: 25em;
  height: 100%;
  object-fit: cover;
  max-width: 25em;
}

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

JS

              
                
import { html, render } from "https://unpkg.com/lit-html@0.12.0/lit-html.js?module";

class ItemDetail {
  
  constructor(renderRoot) {    
    this.renderRoot = renderRoot;
    this.render();
    this.scrim = this.renderRoot.querySelector(".scrim");
    this.image = this.renderRoot.querySelector(".image");
    this.content = this.renderRoot.querySelectorAll(".content");
  }
    
  close() {
    
    const a = this.currentItem.image.getBoundingClientRect();
    const b = this.image.getBoundingClientRect();
    
    const tl = new TimelineMax()
      .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.renderRoot.classList.remove('details--open');
      });
  }
  
  open(item) {
    
    if (this.currentItem) { return; }
        
    this.currentItem = item;
    this.render(item.props);
    
    this.image.style.cssText = "";
    
    const a = item.image.getBoundingClientRect();
    const b = this.image.getBoundingClientRect();
    
    const offset = [5, 10, 20];
    
    const tl = new TimelineMax()    
      .set(this.content, {
        y: i => offset[i]
      })
      .set([item.image, this.content, this.scrim], {
        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.renderRoot.classList.add('details--open');
  }
  
  render({ img = "", title, subtitle, description } = {}) {
    
    const template = html`
      <div class="scrim"></div>
      <button class="close" @click=${this.close}></button>
      <div class="details__inner">
        <img class="image details__img" src="${img}" alt=""/>
        <h2 class="content details__title">${title}</h2>
        <h3 class="content details__subtitle">${subtitle}</h3>
        <p class="content details__description">${description}</p>
      </div>
    `;
    
    render(template, this.renderRoot, { scopeName: "item-detail", eventContext: this });
  }
}


class GridItem {
  
  constructor(renderRoot, props) {
    this.renderRoot = renderRoot;
    this.props = props;    
    this.render(this.props);
    this.image = this.renderRoot.querySelector(".image");
  }
  
  render({ img, title, subtitle, description }) {
    
    const template = html`
      <div class="box" @click=${() => itemDetail.open(this)}>
        <div class="box__bg"></div>
          <img class="image box__img" src="${img}" />
        <h2 class="box__title">${title}</h2>
        <h3 class="box__subtitle">${subtitle}</h3>
        <p class="box__description">${description}</p>
      </div>
    `;
    
    render(template, this.renderRoot, { scopeName: "grid-item", eventContext: this });
  }
}


const data = [
  {
    title: 'Example Title',
    subtitle: 'Subtitle',
    img: 'https://source.unsplash.com/random/500x750',
    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.'
  },
  {
    title: 'A Different Title',
    subtitle: 'Subtitle',
    img: 'https://source.unsplash.com/random/400x450',
    description: 'Velit elit velit dolore amet deserunt enim dolore est sint esse. Cillum et in nulla commodo. Ex sunt anim ut et voluptate sunt irure proident.'
  },
  {
    title: 'A New Title',
    subtitle: 'Subtitle',
    img: 'https://source.unsplash.com/random/600x600',
    description: 'Ex sunt anim ut et voluptate sunt irure proident. Velit elit velit dolore amet deserunt enim dolore est sint esse. Cillum et in nulla commodo.'
  }
];

const itemRoots = document.querySelectorAll(".grid__item");
const detailsRoot = document.querySelector(".details");
const gridItems = data.map((props, i) => new GridItem(itemRoots[i], props));
const itemDetail = new ItemDetail(detailsRoot);
              
            
!
999px

Console