Responsive Gallery Layout Vue Component

Responsive Gallery Layout Vue Component

This is a use of (almost) pure CSS layout components similar adaptive Google Photo picture list; here 近乎actually refers to the proportion of the need to know in advance the picture width or height. Please refer to here for specific principles

Adaptive gallery layout components

This is a use of (almost) pure CSS layout components similar adaptive Google Photo picture list; here 近乎actually refers to the proportion of the need to know in advance the picture width or height. Please refer to here for specific principles

example

example

You can also refer to gallery-layout-example.html in the example folder

Features

  • Each box is stretched proportionally
  • The box will occupy each row in the horizontal direction, without extra space
  • The height of each row remains the same and the bottom is aligned

PS: Adaptive means: height and width are uncontrollable

installation

npm install vue-gallery-layout -s

usage

Partial introduction

import VueGalleryLayout from 'vue-gallery-layout';

// demo.vue
...
export default {
  components: {
    VueGalleryLayout
  }
}

Global introduction

import VueGalleryLayout from 'vue-gallery-layout';
import Vue from 'vue';

Vue.use(VueGalleryLayout);

Broswer introduced

// 全局暴露变量 VueGalleryLayout
<script src="../dist/vue-gallery-layout.js"></script>
<script>
  new Vue({
    el: '#app',
    components: {
      GalleryLayout
    }
  })
</script>

Specific use

<template>
  <div>
    <gallery-layout
      :items="items"
      :box-container-class="boxContainerClass"
      :box-init-ratio="boxInitRatio">
      <template slot-scope="scope">
        <div>{{ scope.item.width }}</div>
      </template>
    </gallery-layout>
  </div>
</template>

<script>
export default {
  //...

  data() {
    return {
      items: [
        {
          {
            id: 1,
            width: 200,
            height: 100
            // ratio: 2
          },
          {
            id: 2,
            width: 300,
            height: 200
            // ratio: 1.5
          }
        }
      ],
      boxContainerClass: 'box-container-margin',
      boxInitRatio: 100
    }
  }
}
</script>

<style>
  .box-container-margin {
    margin: 4px;
  }
</style>

props

  • items: Array<[item...]>
  • item: Object<{width, height, ratio, id}>
  • id: Any identifier
  • width: Number width, required
  • height: Number high, required
  • ratio: Number, width / height, if there is ratio, width and height are not needed
  • boxContainerClass: String, the default is "; box container class
  • boxInitRatio: Number, default 200;
  • Assuming the ratio of most boxes is 2:1, the initial screen width is 1600px, and you want to be able to accommodate 4 boxes in most cases, then your boxInitRatio is less than 200. Note: Due to the existence of self-adaptation, the box contained in each row is actually determined by the ratio of boxInitRatio, item, and the width of each row.

Extension (high-level) components

Download Details:

Author: liuqipeng417

Source Code: https://github.com/liuqipeng417/vue-gallery-layout

vue vuejs javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

8 Popular Websites That Use The Vue.JS Framework

In this article, we are going to list out the most popular websites using Vue JS as their frontend framework. Vue JS is one of those elite progressive JavaScript frameworks that has huge demand in the web development industry. Many popular websites are developed using Vue in their frontend development because of its imperative features.

Vue Native is a framework to build cross platform native mobile apps using JavaScript

Vue Native is a framework to build cross platform native mobile apps using JavaScript. It is a wrapper around the APIs of React Native. So, with Vue Native, you can do everything that you can do with React Native. With Vue Native, you get

How to Make a Simple Vue Custom Select Component

In this article, you’ll learn how to build a Vue custom select component that can be easily be styled using your own CSS. In fact, it’s the same component that we use in production on Qvault, and you can see it in action on the playground.

Creating a Custom Tooltip Component in Vue

There are plenty of libraries out there that will have you up and running with a good tooltip solution in minutes. However, if you are like me, you are sick and tired of giant dependency trees that have the distinct possibility of breaking at any time.

Vue ShortKey plugin for Vue.js

Vue-ShortKey - The ultimate shortcut plugin to improve the UX .Vue-ShortKey - plugin for VueJS 2.x accepts shortcuts globaly and in a single listener.