npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-virtual-masonry

v1.2.7

Published

A virtual masonry component for Vue.

Downloads

94

Readme

vue-virtual-masonry

This is a Vue component for quickly building a virtual scrolling masonry.

Inspired by starkwang's vue-virtual-collection

Install

npm i vue-virtual-masonry

Usage

Firstly, import the component.

import Vue from 'vue';
import VirtualMasonry from 'vue-virtual-masonry';

Vue.use(VirtualMasonry, {
  additionalDistance: 500, // option value
});

The additionalDistance is a additional distance to screen edge to judge if the cells should be visible.

If set to 500, cell will be visible when its top edge reaches 500px below the viewport.

It's the same for cell leaving viewport, if its bottom edge reaches 500px upper the viewport, it will be invisible.

The default value of additionalDistance is 300,

In your page, use the component like this:

<template>
  <div class="masonry">
    <VirtualMasonry :items="items" :colWidth="200" :itemHeightGetter="heightGetter">
      <template slot-scope="props"></template>
    </VirtualMasonry>
  </div>
</template>

The itemHeightGetter is a function in methods, here's an example:

export default {
  methods: {
    heightGetter(item) {
      return item.height;
    },
  },
};

The function should return the height of this item.

If col is not set, component will calculate the columns count automatically by the width of masonry container.

If you want to render a certain columns masonry, you can set the component like this:

<template>
  <div class="masonry">
    <VirtualMasonry
      :items="items"
      :colWidth="200"
      :col="3"
      :fit="true"
      :itemHeightGetter="heightGetter"
    >
      <template slot-scope="props"></template>
    </VirtualMasonry>
  </div>
</template>

It's recommend to set fit true, the container will fit the width of inner content.

You can find more details in the reference.

Reference

Props

items

Type: Array

Required: true

The collecton you want to render in masonry.

colWidth

Type: Number

Required: true

The width of column in masonry.

itemHeightGetter

Type: Function

Required: true

Returns: Number

A function return the height of each cells. It should return a number indicating the height of the cell corresponding to the parameter item.

col

Type: Number

Default: 0

If col is above 0, component will render certain columns you set in masonry.

fit

Type: Boolean

Default: false

Only effect when col is above 0, the width of container will fit inner contents automatically.

gap

Type: Number

Default: 16

The gap of cells in masonry.

rowPerSection

Type: Number

Default: 3

Component will build several sections to simplify the calculation of elements visibility.

By default, 3 rows of cells will be grouped up as a section.

Most of time, this value doesn't need to be modified.

Slot

Default slot is the only slot in the component, it will pass two props that you need use slot-scope to receive it in your code.

Example:

<template slot-scope="props">
  <p>{{ props.data }}</p>
</template>

In this example, props.data is the item in collection which is used to be rendered this cell.

Every data will be added a property named _masonryIndex to show the index of this item in the masonry.

Also, you can get position info from slot, here's an example of position info:

{
  left: 200,  // absolute left position of the cell
  top: 0,  // absolute top position of the cell
  height: 332, // height of the cell
}

License

MIT