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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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
      .box__bg
      img.box__img(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://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.'
    })
    +box({
      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.'
    })
    +box({
      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.'
    })

              
            
!

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;
  
  &: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;
	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;
}

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

JS

              
                class Details {
  constructor() {
    this.DOM = {};
    
    const detailsTemp = `
      <button class="close"></button>
      <div class="details__inner">
        <img class="details__img" src="" alt=""/>
        <h2 class="details__title"></h2>
        <h3 class="details__subtitle"></h3>
        <p class="details__description"></p>
      </div>
    `;
    
    this.tl = new TimelineMax();
    this.DOM.details = document.createElement('div');
    this.DOM.details.className = 'details';
    this.DOM.details.innerHTML = detailsTemp;
    DOM.content.appendChild(this.DOM.details);
    this.init();
  }
  init() {
    this.DOM.close = this.DOM.details.querySelector('.close')
    this.DOM.img = this.DOM.details.querySelector('.details__img');
    this.DOM.title = this.DOM.details.querySelector('.details__title');
    this.DOM.subtitle = this.DOM.details.querySelector('.details__subtitle');
    this.DOM.description = this.DOM.details.querySelector('.details__description');
    
    this.initEvents();
  }
  initEvents() {
    this.DOM.close.addEventListener('click', () => {
      this.close();
    })
  }
  fill(info) {
    this.DOM.img.src = info.img;
    this.DOM.title.innerHTML = info.title
    this.DOM.subtitle.innerHTML = info.subtitle
    this.DOM.description.innerHTML = info.description
  }
  getBoxDetailsRect() {
    return {
      boxImgRect: this.DOM.boxImg.getBoundingClientRect(),
      detailsImgRect: this.DOM.img.getBoundingClientRect()
    };
  }
  open(data){
    if (this.isAnimating) return false;
    this.isAnimating = true;
    
    if (this.DOM.details.classList.contains('details--open')) return false;
    
    this.DOM.details.classList.add('details--open');
    
    this.DOM.boxImg = data.boxImg;
    this.DOM.boxImg.style.opacity = 0;
    
    const rect = this.getBoxDetailsRect();
    
    console.log(rect.boxImgRect);
    console.log(`box top ${rect.boxImgRect.top}`);
    console.log(`details top ${rect.detailsImgRect.top}`);
    
    this.DOM.img.style.opacity = 1;
    
    this.tl
      .fromTo(this.DOM.img, 0.8, {
        x: (rect.boxImgRect.left - rect.detailsImgRect.left),
        y: (rect.boxImgRect.top - rect.detailsImgRect.top)
      },{
        x: 0,
        y: 0
      })
      .fromTo(this.DOM.img, 2, {
        width: rect.boxImgRect.width,
      }, {
        width: '100%',
        clearProps: 'width',
        onComplete: () => (this.isAnimating = false)
      }, 0);
    
    // this.tl.fromTo(this.DOM.img, 0.8, {
    //   height: rect.boxImgRect.height,
    //   width: rect.boxImgRect.width,
    //   x: (rect.boxImgRect.left - rect.detailsImgRect.left),
    //   y: (rect.boxImgRect.top - rect.detailsImgRect.top)
    // },{
    //   width: '100%',
    //   x: 0,
    //   y: 0,
    //   onComplete: () => (this.isAnimating = false)
    // });
  }
  close() {
// TODO: add check later within gsap onComplete
    // if (this.isAnimating) return false;
    // this.isAnimating = true;
    // this.tl.kill();
    
    this.DOM.details.classList.remove('details--open');
    const rect = this.getBoxDetailsRect();
    
    // this.DOM.img.style.opacity = 0;
    // this.DOM.img.style.transform = 'none';
    
    this.DOM.boxImg.style.opacity = 1;
  }
}

class Item {
  constructor(el) {
    this.DOM = {};
    this.DOM.el = el;
    this.DOM.box = this.DOM.el.querySelector('.box');
    this.DOM.boxImg = this.DOM.box.querySelector('.box__img');
    
    this.info = {
      img: this.DOM.boxImg.src,
      title: this.DOM.box.querySelector('.box__title').innerHTML,
      subtitle: this.DOM.box.querySelector('.box__subtitle').innerHTML,
      description: this.DOM.box.querySelector('.box__description').innerHTML,
    }
    
    this.initEvents();
  }
  
  initEvents() {
    this.DOM.box.addEventListener('click', () => this.open());
  }
  
  open() {
    DOM.details.fill(this.info);
    DOM.details.open({
      boxImg: this.DOM.boxImg
    })
  }
}

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

DOM.details = new Details();
              
            
!
999px

Console