A new masonry component powered by CSS to be fast loading and free of jQuery or other dependencies. Build specifically for Vue.js projects.
Existing solutions like Vue wrapped DeSandro Masonry, while popular, donât actually leverage Vueâs highly optimized Virtual DOM renderer and in DeSandro Masonryâs case, actually renders elements twice before showing the layout. All of this is ok but we found it to lead to a slow, âlaggyâ user experience that would occasionally miss-render our layout.
Our need for a simple Masonry layout that was fast, used Vueâs Virtual DOM without needing jQuery or other dependencies led us to explore what we could do with the latest techniques using just CSS within a React Component.
Between flexbox, css columns, css grid we settled on plain olâ divâs and a dab of flexbox that allows for âfluidâ responsive layouts by default but most importantly is true to Vueâs rendering lifecycle.
vue-masonry-css
Is a Vue Component with a simple interface to order items into the desired columns at specified breakpoints. With minimal CSS this leads to a quick, reliable solution that also has great browser support along with fast rendering performance ..just as Vue.js intended.
đ What does this do
đłď¸ What doesnât this do
Add vue-masonry-css
to your project:
By script..
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue-masonry-css"></script>
Or as a module⌠npm install vue-masonry-css --save-dev
import Vue from 'vue'
import VueMasonry from 'vue-masonry-css'
Vue.use(VueMasonry);
In your HTML templateâŚ
<masonry
:cols="3"
:gutter="30"
>
<div v-for="(item, index) in items" :key="index">Item: </div>
</masonry>
Different columns and gutter sizes can be specified by passing an object containing keyâs of the window widths and their values representing the number of columns or gutter size. To have a fallback value, use the default
key.
note: The cols=
attribute needs to use Vues bind method to evaluate objects. Instead of cols=""
use either v-bind:cols="{ 700: 3 }"
or the shorthand :cols="{ 700: 3 }"
<masonry
:cols="{default: 4, 1000: 3, 700: 2, 400: 1}"
:gutter="{default: '30px', 700: '15px'}"
>
<div v-for="(item, index) in items" :key="index">Item: </div>
</masonry>
In the above example, the number of columns will default to 4. When the windowâs is between 1000px and 700px, the number of columns will be 3. The key represents the max-width
of the window, and vue-masonry-css
will use the largest key that satisfies this.
https://paulcollett.github.io/vue-masonry-css/demo/
https://github.com/paulcollett/vue-masonry-css
Contact me direct: