cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              <div id="app" class="container text-center">  
  <div class="gallery">
    <h1>{{ title }} <small>Vue.js</small></h1>    
    <div class="row">
      <div v-for="photo in photos" class="photo-frame" @click="showPhoto(photo.id)">   
        <div class="photo" :style="{ backgroundImage: 'url(' + photo.urlThumbnail + ')' }"></div>      
      </div>    
    </div>
    <div class="row">
      <div class="pager-frame">
        <ul class="pager-frame">
          <li v-for="page in idxLastPage" class="page" :class="{ active: (idxCurrentPage+1) == page }" @click="paginate(page-1)">
            <a href="#">{{ page }}</a> 
          </li>         
        </ul>           
      </div>
    </div>
  </div>  
  <div id="overlay" v-show="isShowPhoto" @click="isShowPhoto=false"></div>  
  <div id="layout" v-show="isShowPhoto" @click="isShowPhoto=false">
    <img :src="showPhotoUrl" alt="">
    <div class="prev" @click.stop="goPrevPhoto()">&lt;</div>
    <div class="next" @click.stop="goNextPhoto()">&gt;</div>
    <div class="status">
      {{ idxCurrentPhoto+1 }} / {{ idxLastPhoto+1 }}
    </div>
  </div>  
</div>

<div class="container-fluid footer text-center">    
  <p>A teljes cikket elolvashatod az ITHub-on. Klikkelj a logóra alább!</p>
  <p><em>You can read the Hungarian full article on the ITHub. Click the logo below!</em></p>
  <a href="https://ithub.hu/blog/post/Ismerkedes-a-Vuejs-keretrendszerrel---2-resz---Urlapok-komponensek/" target="ithub">
    <img src="https://ithub.hu/images/ithub-logo-dark.png" alt="ithub logo" style="width: 85px; height: auto;">    
  </a>  
</div>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=PT+Sans+Narrow');

body {
  font-family: 'PT Sans Narrow', sans-serif;
}  

.container {
  max-width: 1500px;
  margin: 10px auto;
  clear: both;   
}

.text-center {
  text-align: center;
}
  
.gallery {    
  h1 {
   font-size: 3em; 
   color: #226;
    small {
      font-size: 1em;
      color: #888;
    }
  }
  
  .photo-frame {
    width: 310px;
    height: 210px;
    padding: 5px;
    border: 1px solid #eee;
    background-color: #fafafa;
    margin: 5px;
    float: left;
    cursor: pointer;
  
    .photo {
      width: 300px;
      height: 200px;
      border: 1px solid #aaa;
      padding-left: 5px;
      padding-top: 5px;
      overflow: hidden;      
      background-position: top center;
      background-size: cover;
    }  
  }     
}

div.row {
  clear: both;
}

ul.pager-frame {    
  display: inline-block;
  clear: both;
  text-align: center;
  list-style-type: none;

  li.page {
    width: 40px;
    border-radius: 50px 50px;
    border: 1px solid #888;
    float: left;
    margin-left: 20px;

    &:hover {
        background-color: #ccc;
        cursor: pointer;
      }

    a {
      text-decoration: none;
      color: #222;        
    }

    font-size: 2em;      
    &.active {
      background-color: #ddd;
    }
  }
}

#overlay {  
  position: fixed;
  z-index: 10;  
  left: 0px;
  top: 0px;
  width: 100%;
  height: 100%;
  text-align: center;  
  background: rgba(0, 0, 0, 0.7); 
  text-align: center;
}

#layout {  
  z-index: 11;
  position: absolute;
  top: 0;
  left: 0;
  width: 95%;      
  margin-top: 50px;
  text-align: center;    

  img {
    margin: 40px auto 0;
    max-width: 1260px;                  
    width: 100%;                
    border: 1px solid #aaa;
    box-shadow: 0 0 10px black;
  }            
  
  .next, .prev {    
    position: absolute;    
    top: 70px;    
    width: 40px;
    height: 30px;
    border: 2px solid #ffffff88;
    border-radius: 50px 50px;
    box-shadow: 2px 2px 10px black;    
    padding-top: 10px;
    color: white;
    text-shadow: 2px 2px 10px black;
    cursor: pointer;
    
    &:hover {
      background-color: #ffffff22;
      border-color: #ffffff;
    }
  }
    
  .prev {
    left:20px; 
  }
  
  .next {
    right:20px; 
  }
  
  .status {
    position: absolute;    
    top: 70px;  
    right: 100px;
    width: 50px;
    height: 30px;
    border: 2px solid #ffffff88;
    border-radius: 5px;
    box-shadow: 2px 2px 10px black;    
    padding-top: 10px;
    color: white;
    text-shadow: 2px 2px 10px black;    
    background-color: #ffffff88;
  }
}

/** footer ***/

.container-fluid {  
  width: 100%;
  margin: 10px 0;
  clear: both;   
}

.footer {
  background-color: #1B1C1D;
  padding: 10px 10px;;
  color: white;
  font-size: 20px;
  font-family: arial;
  text-height: 40px;
  
  em {
    color: #aaa;  
  }
  
  a {
    display: inline-block;
    border: 1px solid #aaa;
    border-radius: 10px;
    padding: 10px;    
    color: #ddd;
    text-decoration: none;    
  }
}
            
          
!
            
              var allPhotos = getPhotos();

new Vue({
  el: '#app',
  data: {
    title: 'Collection of Awesome Girls',
    allPhotos: allPhotos, // all photos
    photos: [],           // photos in the current page
    photosPerPage: 12,    // photos per page
    idxLastPhoto: 0,      // last photo's id
    idxCurrentPage: 0,    // current photo's id
    idxLastPage: 0,       // last page's id      
    isShowPhoto: false,   // 
    showPhotoUrl: '',     // selected photo url
    idxCurrentPhoto: 0    // current photo index
    
  }, 
  mounted: function() {    
    // init indexes
    this.idxLastPhoto = this.allPhotos.length-1;
    this.idxLastPage = Math.floor(this.allPhotos.length / this.photosPerPage); 
    
    // show first page
    this.paginate(0);
    
    document.addEventListener("keydown", e => {
      if (this.isShowPhoto && e.keyCode == 27) {
          this.isShowPhoto = false;
      }
    });
  },
  methods: {
    /** Paginate photos / Rebuild photos array
     *
     */
    paginate: function(idxPage) {
      this.idxCurrentPage = idxPage;
      
      // determine period
      var idxStart = Math.floor(idxPage*this.photosPerPage); 
      var idxEnd = idxStart+this.photosPerPage>this.idxLastPhoto+1?this.idxLastPhoto:idxStart+this.photosPerPage;      
      
      // drop the visible photos
      this.photos.splice(0, this.photos.length)      
      
      // reload visible photos from all photo
      for(var idx = idxStart; idx < idxEnd; idx++) {
        this.photos.push(this.allPhotos[idx]);                 
      }
    },
    
    /**
     * Show image preview larger
     */
    showPhoto: function(id) {            
      var that = this;
      
      // find photo data by id
      this.allPhotos.forEach(function(photo, idx) {
        if (photo.id === id) {     
          // lock background and show photo
          that.isShowPhoto = true;    
          that.showPhotoUrl = photo.urlPhoto;      
          that.idxCurrentPhoto = idx;
          
          // go top of the page
          window.scrollTo(0,0);
        }
      });
    },
    goPrevPhoto: function() {
      var current = this.idxCurrentPhoto;      
      this.showPhoto(this.allPhotos[current === 0 ? this.idxLastPhoto : current-1].id);
      
    },
    goNextPhoto: function() {
      var current = this.idxCurrentPhoto;      
      this.showPhoto(this.allPhotos[current === this.idxLastPhoto ? 0 : current+1].id);      
    }
  }
});

/**
 * Get photos from pexels.com and generate urls by ids
 * @return array [{urlThumbnail, urlPhoto, idx}, ...]
 */
function getPhotos() {
  var pexelIds = [
    289225, 866019, 255349, 864939, 864990, 675927, 206529, 413727, 413998, 858117, 293029, 826349,
    247199, 255332, 945813,  265705,  247298, 906052, 654690, 863977, 732420, 573299, 415829, 247322, 
    207936, 394545, 594365, 715840, 819469, 746825,  413885, 774367, 269746, 206388, 235516, 805367
  ];

  var photos = [];
  pexelIds.forEach(function(id) {    
    photos.push({
      urlPhoto: 'https://images.pexels.com/photos/'+id+'/pexels-photo-'+id+'.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb',
      urlThumbnail: 'https://images.pexels.com/photos/'+id+'/pexels-photo-'+id+'.jpeg?w=400&h=400&auto=compress&cs=tinysrgb',
      id: id
    });  
  });
  
  return photos;
};
            
          
!
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.
Loading ..................

Console