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

              
                <!-- Blocking page render before all image loads is not a good idea -->
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1vtaubItASKilyvb5sgQO7D7gjAQ7xo0i'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1FJNbSIMKRPBnGPienoYK1Qf8wIwQSdpR'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1TODQyZgnCjDX2Slr0ll8g-ymIV8Yizkh'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1UToQfe_NtiiiuMmEe0pTklSJVX5fMfjx'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1k9fwXuTvRq31IiIottNXyLXVmp_AlSqY'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1cLTEsyaPIfpbY0cDBVGWNcAJkYQiKkDy'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1XVFuCCK-H7Bsl6MElKsTonRS3LFwVeKr'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1iEEkhqhXHMwYEU_OZXFNy4WVJd8XgKeF'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1YQoo8tP26iVhQYzdOoul0GXX7VGhwxcy'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1phnVR5D_T1I5zbGglRQvQKwqwO8OK8g8'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1EkdV0pffOX-icwcJPJfEl8f8J9v1uKoO'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1jw8973CNvmfp2mocKx8XgCnfU9BUAB5o'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1mklqc080uvbzidP1ZUT_v_INLvphiM2z'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=16kYP2us-BsJOflHdPnhPeyUavGrrYLKr'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1IQHncfdA2iU1YIdQndggvmoLIOIhc1he'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=15h11jLQqXTHnFdruo2Ahz-DQf_KQj3vW'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1ktnwX9h1O27dQEKtZt78f4rDv1AIbnFS'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1owtgIhe8hFVF2LLhldAf1rODrurgv7OQ'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1i1VvCV1D00qLJFBjKqF_D837dnav6lLR'>
    <link rel="preload" as="image" href='https://drive.google.com/uc?id=1D7PBddCxxb6aRk43maJ_BXgQD-PRS6R7'>

<div class='container'>
  <div class='image-container'></div>
  <div class='text-container'>
    <div class='subtitle' id='line1'>These lines float in one by one</div>
    <div class='title' id='line2'>How to make</div>
    <div class='title' id='line3'>Moving background</div>
    <div class='subtitle' id='line4'>Disappear again when scroll top</div>
  </div>
</div>
              
            
!

CSS

              
                // Color

body {
  margin: 0;
  font-family: 'Permanent Marker', cursive;
}

.container {
  position: relative;
  width: 100%;
  height: 1500px;

  .image-container {
    width: 100%;
    height: 0;
    padding-top: 45.347%;
    position: sticky;
    top: 0;
    background-size: cover;
    background-image: url('https://drive.google.com/uc?id=1vtaubItASKilyvb5sgQO7D7gjAQ7xo0i');
  }
  
  .text-container {
    width: 100%;
    height: 100%;
    position: fixed;
    display: flex;
    flex-direction: column;
    justify-content:center;
    align-items: center;
    top: 0;
    color: white;
    .subtitle { 
      opacity: 0;
      font-size: 30px; 
    }
    .title { 
      opacity: 0;
      font-size: 80px; margin: -20px 0;
    }
  }
}
              
            
!

JS

              
                // Images asset
const fruitImages = {
    1:'https://drive.google.com/uc?id=1vtaubItASKilyvb5sgQO7D7gjAQ7xo0i',
    2:'https://drive.google.com/uc?id=1FJNbSIMKRPBnGPienoYK1Qf8wIwQSdpR',
    3:'https://drive.google.com/uc?id=1TODQyZgnCjDX2Slr0ll8g-ymIV8Yizkh',
    4:'https://drive.google.com/uc?id=1UToQfe_NtiiiuMmEe0pTklSJVX5fMfjx',
    5:'https://drive.google.com/uc?id=1k9fwXuTvRq31IiIottNXyLXVmp_AlSqY',
    6:'https://drive.google.com/uc?id=1cLTEsyaPIfpbY0cDBVGWNcAJkYQiKkDy',
    7:'https://drive.google.com/uc?id=1XVFuCCK-H7Bsl6MElKsTonRS3LFwVeKr',
    8:'https://drive.google.com/uc?id=1iEEkhqhXHMwYEU_OZXFNy4WVJd8XgKeF',
    9:'https://drive.google.com/uc?id=1YQoo8tP26iVhQYzdOoul0GXX7VGhwxcy',
    10:'https://drive.google.com/uc?id=1phnVR5D_T1I5zbGglRQvQKwqwO8OK8g8',
    11:'https://drive.google.com/uc?id=1EkdV0pffOX-icwcJPJfEl8f8J9v1uKoO',
    12:'https://drive.google.com/uc?id=1jw8973CNvmfp2mocKx8XgCnfU9BUAB5o',
    13:'https://drive.google.com/uc?id=1mklqc080uvbzidP1ZUT_v_INLvphiM2z',
    14:'https://drive.google.com/uc?id=16kYP2us-BsJOflHdPnhPeyUavGrrYLKr',
    15:'https://drive.google.com/uc?id=1IQHncfdA2iU1YIdQndggvmoLIOIhc1he',
    16:'https://drive.google.com/uc?id=15h11jLQqXTHnFdruo2Ahz-DQf_KQj3vW',
    17:'https://drive.google.com/uc?id=1ktnwX9h1O27dQEKtZt78f4rDv1AIbnFS',
    18:'https://drive.google.com/uc?id=1owtgIhe8hFVF2LLhldAf1rODrurgv7OQ',
    19:'https://drive.google.com/uc?id=1i1VvCV1D00qLJFBjKqF_D837dnav6lLR',
    20:'https://drive.google.com/uc?id=1D7PBddCxxb6aRk43maJ_BXgQD-PRS6R7',
}
// Text style
const textStyle = {
  1: {opacity: 0, transform: '0px'},
  2: {opacity: 0, transform: '0px'},
  3: {opacity: 0, transform: '0px'},
  4: {opacity: 0, transform: '0px'},
  5: {opacity: .25, transform: '15px'},
  6: {opacity: .5, transform: '10px'},
  7: {opacity: .75, transform: '5px'},
  8: {opacity: 1, transform: '0px'},
  9: {opacity: 1, transform: '0px'},
  10: {opacity: 1, transform: '0px'},
  11: {opacity: 1, transform: '0px'},
  12: {opacity: 1, transform: '0px'},
  13: {opacity: 1, transform: '0px'},
  14: {opacity: 1, transform: '0px'},
  15: {opacity: 1, transform: '0px'},
  16: {opacity: 1, transform: '0px'},
  17: {opacity: 1, transform: '0px'},
  18: {opacity: 1, transform: '0px'},
  19: {opacity: 1, transform: '0px'},
  20: {opacity: 1, transform: '0px'},
}

// Global variable to control the scrolling behavior
const step = 30; // For each 30px, change an image

function trackScrollPosition() {
  const y = window.scrollY;
  const label = Math.min(Math.floor(y/30) + 1, 20);
  const imageToUse = fruitImages[label];
  // Change the background image
  $('.image-container').css('background-image', `url('${imageToUse}')`);
  // Change the text style
  const textStep = 2;
  const textStyleToUseLine1 = textStyle[label];
  const textStyleToUseLine2 = textStyle[Math.min(Math.max(label - textStep, 1), 20)];
  const textStyleToUseLine3 = textStyle[Math.min(Math.max(label - textStep * 2, 1),20)];
  const textStyleToUseLine4 = textStyle[Math.min(Math.max(label - textStep * 3, 1),20)];
  $('#line1').css({'opacity': textStyleToUseLine1.opacity, 'transform': `translateY(${textStyleToUseLine1.transform})`});
  $('#line2').css({'opacity': textStyleToUseLine2.opacity, 'transform': `translateY(${textStyleToUseLine2.transform})`});
  $('#line3').css({'opacity': textStyleToUseLine3.opacity, 'transform': `translateY(${textStyleToUseLine3.transform})`});
  $('#line4').css({'opacity': textStyleToUseLine4.opacity, 'transform': `translateY(${textStyleToUseLine4.transform})`});

}

$(document).ready(()=>{
  // register an event listener on window
  $(window).scroll(()=>{
    // We don't need to use 'event' as the scroll exist in window
    trackScrollPosition();
  })
})
              
            
!
999px

Console