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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                section#section1
  .section-grid
    .left
      .grid-text
        p Lorem, ipsum dolor sit amet consectetur adipisicing elit. Facilis consequuntur officia laboriosam error. Illum numquam est labore suscipit deserunt voluptate aspernatur dolorem, ipsam recusandae cupiditate itaque omnis eum fuga iste?
    .right
      .grid-image.image-1.active
        img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/495197/0st9yhngses-benjamin-child.jpg")

section#section2
  .section-grid
    .left
      .grid-text
        p Lorem, ipsum dolor sit amet consectetur adipisicing elit. Facilis consequuntur officia laboriosam error. Illum numquam est labore suscipit deserunt voluptate aspernatur dolorem, ipsam recusandae cupiditate itaque omnis eum fuga iste?
    .right
      .grid-image.image-2.active
        img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/495197/2fgvaqx-fxs-oskar-krawczyk.jpg")

section#section3
  .section-grid
    .left
      .grid-text
        p Lorem, ipsum dolor sit amet consectetur adipisicing elit. Facilis consequuntur officia laboriosam error. Illum numquam est labore suscipit deserunt voluptate aspernatur dolorem, ipsam recusandae cupiditate itaque omnis eum fuga iste?
    .right
      .grid-image.image-3.active
        img(src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/495197/Great_Wave_off_Kanagawa2_cr.jpg")
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Montserrat:400,400i,700")

body
  font-family: Montserrat, sans-serif
  line-height: 1.4

img
  width: 200px
  display: block
  box-shadow: 0px 0px 30px 0px rgba(black, 0.3)
  
  @media (min-width: 700px)
    width: 400px
    
  @media (min-width: 1000px)
    width: 600px
  
.section-grid
  display: grid
  // Responsive, 1/3 - 2/3 split
  grid-template-columns: 1fr 2fr
  height: 100vh
  
.left,
.right
  // Center the elements in each column
  display: flex
  justify-content: center
  align-items: center
  
.grid-text
  padding: 1rem
  position: relative
  // Flexbox centers the paragraph element
  display: flex
  justify-content: center
  align-items: center
  height: 100%

.grid-image
  // keeps the image fixed on scroll
  position: fixed
  z-index: 100
  
.image-1,
.image-2,
.image-3
  opacity: 0
  
  &.active
    animation: fadeIn 1000ms ease forwards
    opacity: 1
    
    
@keyframes fadeIn 
  0%
    opacity: 0
  100%
    opacity: 1
              
            
!

JS

              
                // find the top of each section
var section1 = $('#section1').offset().top;
var section2 = $('#section2').offset().top;
var section3 = $('#section3').offset().top;

// number of pixels before the section to change image
var scrollOffset = 300;


// run this function when the window scrolls
$(window).scroll(function() {  
  
   
  // get the window height on scroll
  var scroll = $(window).scrollTop() + scrollOffset;  
  

  // if scroll hits the top of section 1  
  if ( scroll < 500 ) {
    $('.grid-image img').attr('src', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/495197/0st9yhngses-benjamin-child.jpg');
  }
  
  // if scroll hits the top of section 2
  if ( scroll > section2 ) {
    $('.grid-image img').attr('src', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/495197/2fgvaqx-fxs-oskar-krawczyk.jpg');
  }

  // if scroll hits the top of section 3
  if ( scroll > section3 ) {
    $('.grid-image img').attr('src', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/495197/Great_Wave_off_Kanagawa2_cr.jpg');
  }
});



              
            
!
999px

Console