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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div class="container">
  <div class="gallery-one">
    <img src="https://images.unsplash.com/photo-1492136344046-866c85e0bf04?dpr=1&auto=format&fit=crop&w=1000&q=80&cs=tinysrgb&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D" alt="paris">
    <div class="overlay"></div>
    <h1 class="text">Paris</h1>
  </div>
  <div class="gallery gallery-two">
    <img src="https://images.unsplash.com/photo-1454793147212-9e7e57e89a4f?auto=format&fit=crop&w=614&q=80&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D" alt="london">
    <div class="overlay"></div>
    <h1 class="text">London</h1>
  </div>
  <div class="gallery gallery-three">
    <img src="https://images.unsplash.com/photo-1506158669146-619067262a00?auto=format&fit=crop&w=1050&q=80&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D" alt="shanghai">
    <div class="overlay"></div>
    <h1 class="text">Shanghai</h1>
  </div>
  <div class="gallery gallery-four">
    <img src="https://images.unsplash.com/photo-1483070472046-4defb528eff3?auto=format&fit=crop&w=1050&q=80&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D" alt="singapore">
    <div class="overlay"></div>
    <h1 class="text">Singapore</h1>
  </div>
  <div class="gallery gallery-five">
    <img src="https://images.unsplash.com/photo-1423655156442-ccc11daa4e99?auto=format&fit=crop&w=1050&q=80&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D" alt="newyork">
    <div class="overlay"></div>
    <h1 class="text">New York</h1>
  </div>
  <div class="filler"></div>
</div>


<a class="link" 
   target="_blank" 
   href="http://hakilebara.com">hakilebara</a>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}
img {
  width: 100%;
}
body {
  align-items: center;
  background-color: #7A2EB8;
  display: flex;
  font-family: sans-serif;
  height: 100vh;
  justify-content: center;
  margin: 0;
}
.container {
  background-color: #152638;
  box-shadow: 0px 10px 30px 0px rgba(50, 50, 50, 0.53);  
  height: 590px;
  overflow-y: auto;
  overflow-x: hidden;
  width: 330px;
 
}
.gallery {
  height: 148px;
  overflow: hidden;
  position: relative;
  transform-origin: bottom;
  transition: .3s;
  will-change: transform;
}

.gallery img {
  height: 334px;
  object-fit: cover;
  transform-origin: top;
  transition: .3s;
  will-change: transform;
}


.gallery .overlay,
.gallery-one .overlay {
  background-color: #000;
  opacity: 0;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  transition: .4s;
  will-change: opacity;
}
.gallery .overlay {
  opacity: .5;
}

.gallery .text,
.gallery-one .text{
  align-items: center;
  color: #FFF;
  display:  flex;
  justify-content: center;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  will-change: transform;
  transition: transform .4s;
}
.gallery .text {
  font-size: 1.125em;
}

.gallery-one {
  background-color: #dadaed;
  height: 334px;
  overflow: hidden;
  position: relative;
  transition: .4s;
  will-change: height;
}
.gallery-one img {
  height: 100%;
  object-fit: cover;
  transition: transform .5s ease-out;
  transform-origin: center;
  will-change: transform;
}
.gallery-one .text {
  font-size: 1.125em;
  transform: scale(2);
}

.gallery.grow {
  transform: scaleY(2.256);
}
.gallery.grow img{
  /* 
  * scale down the image height proportionaly 
  * to it's container.
  * this creates a slide-up effect rather than
  * a stretch
  */
  transform: scaleY(.443); 
}

.gallery.grow .overlay {
  opacity: 0;
}
.gallery.grow .text {
  transform: scaleY(.443);
  transform: scaleX(2);
}
.filler {
  height: calc(100vh - 334px);
  background-color: #152638;
}

/* 
* Darken galleries when they are scrolled over
* the viewport, except from the last gallery
*/
.gallery:not(:nth-last-child(2)).grow.darken .overlay {
  opacity: .5;
}
.gallery:not(:nth-last-child(2)).grow.darken .text{
  transform: scaleY(.443);
}


.gallery-two {background-color: #bcbcde;}
.gallery-three {background-color: #9d99ce;}
.gallery-four {background-color: #7368b8;}
.gallery-five {background-color: #4f2395;}


.link {
  background-color: #000;
  color: #FFF;
  padding: 10px 10px;
  letter-spacing: .125em;
  position: absolute;
  bottom: 30px;
  right: 0px;
  text-decoration: none;
  text-transform: uppercase;
  font-size: .7em
}
              
            
!

JS

              
                /**
* Darken the first gallery on scroll down
* depends on IntersectionObserver being available
*/
let options = {
  threshold: [1, .95, .9, .8],
  rootMargin: '10px 0px 0px 0px'
};
let callback = function(entries, observer) {
  let target = entries[0].target;
  let ratio = entries[0].intersectionRatio;
  if(ratio <= .80) {
    target.querySelector('.overlay').style.opacity = .5;
    target.querySelector('.text').style.transform = ("scale(1)");
  } else {
    target.querySelector('.overlay').style.opacity = 0;
    target.querySelector('.text').style.transform = ("scale(2)");
  }
};
if ('IntersectionObserver' in window) {
  let observer = new IntersectionObserver(callback, options);
  let target = document.querySelector('.gallery-one');
  observer.observe(target);
}


/**
* Create a rubber band effect on the first gallery
*/
window.onload = function() {
  var lastY = 0;
  var initialY;
  let galleries = document.querySelectorAll('.gallery');
  let main = document.querySelector('.main');
  let firstPhoto = document.querySelector('.gallery-one img');
  let galleryOne = document.querySelector('.gallery-one');

  scrollable = document;
  window.addEventListener('touchstart', e => {
    initialY = e.touches[0].clientY;
  });
  window.addEventListener('touchend', e => {
    initialY = 0;
    galleryOne.style.height = "334px";
    firstPhoto.style.transform = (`scale(1)`);
  });
  window.addEventListener('touchmove', e => {
    let currentY = e.touches[0].clientY;
    if(currentY > lastY && window.scrollY <= 0){
      // moving down
      galleryOne.style.height = "400px"
    }
    lastY = currentY;
  });
}

/**
* Expand and reduce galleries on scroll
*/
let galleries = document.querySelectorAll('.gallery');
let container = document.querySelector('.container');

container.addEventListener('scroll', e => {
  galleries.forEach(gallery => {
    let clientY = gallery.getBoundingClientRect().bottom;
    // expandedGalleryHeight = 334px;
    // reducedGalleryHeight = 148px;
    let deltaY = (clientY - 334 - 148) * -1;
    if (deltaY >= 37 && deltaY < 180) {
      gallery.classList.add("grow");
      gallery.classList.remove("darken");
    }
    if (deltaY >= 180) {
      gallery.classList.add("darken");
    }
    else if (deltaY <= 1){
      gallery.classList.remove("grow");
      gallery.classList.remove("darken");
    }
  });
});

              
            
!
999px

Console