123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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.

            
              <div id="app">
   <!-- preloader -->
   <transition name="fade">
      <div class="preloader" v-if="!show">
         <span class="loader"></span>
      </div>
   </transition>
   <!-- /preloader -->
   <!-- section -->
   <section class="section">
      <!-- content -->
      <transition name="slide-fade">
         <div class="content" v-if="show">
            <h1 class="title is-1">VueJS implementation of infinite scrolling.</h1>
            <h2 class="subtitle is-4">See <a target="_blank" href="https://laracasts.com/discuss/channels/vue/infinite-scrolling-in-vue">Infinite scrolling in Vue</a> question at Laracasts Forums.</h2>
            <article class="box" v-for="item in sliced" :key="item.id" v-if="sliced">
               <h1 v-text="item.title"></h1>
               <div v-html="item.content"></div>
            </article>
            <!-- end -->
            <transition name="fade-slow">
               <div class="notification is-info" v-if="end">
                  <p>No more resources!</p>
               </div>
            </transition>
            <!-- /end -->
         </div>
      </transition>
      <!-- /content -->
   </section>
   <!-- /section -->
</div>
<!-- /app -->
            
          
!
            
              * { box-sizing: border-box; }
//
// Loader
.preloader {
  position: absolute;
  top: 0;
  left: 0;
  background-color: hsl(348, 100%, 61%);
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  overflow: hidden;
}
.loader {
  height: 4rem;
  width: 4rem;
  border: 2px solid white;
  border-right-color: transparent;
  border-top-color: transparent;
}
#app {
   max-width: 666px;
   margin-left: auto;
   margin-right: auto;
}
//
// Slide Fade
.slide-fade-enter-active {
  transition: all .3s ease;
}
.slide-fade-leave-active {
  transition: all .3s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}
.slide-fade-enter,
.slide-fade-leave-to {
  transform: translateX(10px);
  opacity: 0;
}
//
// Fade
.fade-enter-active,
.fade-leave-active {
  transition: opacity .3s;
}
.fade-enter,
.fade-leave-to {
  opacity: 0;
}
//
// Fade slow
.fade-slow-enter-active,
.fade-slow-leave-active {
  transition: opacity 3s;
}
.fade-slow-enter,
.fade-slow-leave-to {
  opacity: 0;
}
            
          
!
            
              // example demo content
let lorem = `<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Modi hic obcaecati illo maxime nam illum recusandae corporis maiores excepturi unde sapiente vero odit nihil laborum perferendis omnis, facilis deserunt neque!</p><p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Modi hic obcaecati illo maxime nam illum recusandae corporis maiores excepturi unde sapiente vero odit nihil laborum perferendis omnis, facilis deserunt neque!</p><p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Modi hic obcaecati illo maxime nam illum recusandae corporis maiores excepturi unde sapiente vero odit nihil laborum perferendis omnis, facilis deserunt neque!</p><p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Modi hic obcaecati illo maxime nam illum recusandae corporis maiores excepturi unde sapiente vero odit nihil laborum perferendis omnis, facilis deserunt neque!</p>`;

const app = new Vue({
   el: "#app",
   data: {
      show   : false, // display content after API request
      offset : 5,     // items to display after scroll
      display: 5,     // initial items
      trigger: 300,   // how far from the bottom to trigger infinite scroll
      items  : [],    // server response data
      end    : false, // no more resources
   },
   computed: {
      // slice the array of data to display
      sliced() {
         return this.items.slice(0, this.display);
      },
   },
   methods: {
      // check to see if we're at the bottom of the page
      scroll() {
         window.onscroll = ev => {
            if (
               window.innerHeight + window.scrollY >=
               (document.body.offsetHeight - this.trigger)
            ) {
               if (this.display < this.items.length) {
                  this.display = this.display + this.offset;
               }
               else {
                  this.end = true;
               }
            }
         };
      },
      // preform API request to the server
      fetch() {
         window.setTimeout(() => {
            // example response data
            this.items = [
               { id: 1, title: "Example 1", content: lorem },
               { id: 2, title: "Example 2", content: lorem },
               { id: 3, title: "Example 3", content: lorem },
               { id: 4, title: "Example 4", content: lorem },
               { id: 5, title: "Example 5", content: lorem },
               { id: 6, title: "Example 6", content: lorem },
               { id: 7, title: "Example 7", content: lorem },
               { id: 8, title: "Example 8", content: lorem },
               { id: 9, title: "Example 9", content: lorem },
               { id: 10, title: "Example 10", content: lorem },
               { id: 11, title: "Example 11", content: lorem },
               { id: 12, title: "Example 12", content: lorem },
               { id: 13, title: "Example 13", content: lorem },
               { id: 14, title: "Example 14", content: lorem },
               { id: 15, title: "Example 15", content: lorem },
               { id: 16, title: "Example 16", content: lorem },
               { id: 17, title: "Example 17", content: lorem },
               { id: 18, title: "Example 18", content: lorem },
            ];
            this.show = true;
         }, 2000);
      }
   },
   mounted() {
      // track scroll event
      this.scroll();
   },
   created() {
      // get the data by performing API request
      this.fetch();
   }
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console