A Pure Vue Native Horizontal List Implementation for Mobile/touch and Responsive Web

A Pure Vue Native Horizontal List Implementation for Mobile/touch and Responsive Web

A pure vue native horizontal list implementation for mobile/touch and responsive web. Check it out here: fuxingloh.github.io/vue-horizontal-list.

Vue Horizontal List

A pure vue native horizontal list implementation for mobile/touch and responsive web. Check it out here: fuxingloh.github.io/vue-horizontal-list.

I created this because I like how AirBnb does their horizontal list, I couldn't find a library that is simple and close to it.

vue-horizontal-list screenshot

Installation

npm i vue-horizontal-list
# or
yarn add vue-horizontal-list
Basic usage
<vue-horizontal-list
  :items="items"
  :options="{
    responsive: [
      { end: 576, size: 1 },
      { start: 576, end: 768, size: 2 },
      { size: 3 },
    ],
  }"
>
  <template v-slot:default="{item}">
    <div class="item">
      <h5>{{item.title}}</h5>
      <p>{{item.content}}</p>
    </div>
  </template>
</vue-horizontal-list>

Features

  • Lightweight implementation with 1 dependencies.
  • SSR supported
  • Mobile touch screen friendly
  • Invisible scroll bar for consistent Windows and MacOS browsing experience.
  • Snap to the nearest item in the horizontal-list when scrolling.
  • Windowed & Full-screen mode
    • The windowed mode will respect the container and not show overflowing item
    • Full-screen mode will show overflowing item, best result for small screen
  • Dynamic responsive breakpoint configuration
  • Navigation control will show up dynamically for larger screen
  • Touch screen friendly
  • Slideshow autoplay by @Draccano.
  • Slot different content at the beginning, or the ending of the items list by @Draccano.
  • Minimal config setup
  • Tested on chrome, edge and safari
  • Demo
  • Examples

All available options

const options = {
  item: {
    // css class to inject into each individual item
    class: "",
    // padding between each item
    padding: 12,
  },
  list: {
    // css class for the parent of item
    class: "",
    // maximum width of the list it can extend to before switching to windowed mode, basically think of the bootstrap container max-width
    // windowed is used to toggle between full-screen mode and container mode
    windowed: 1200,
    // padding of the list, if container < windowed what is the left-right padding of the list
    // during full-screen mode the padding will added to left & right to centralise the item
    padding: 24,
  },
  responsive: [
    // responsive breakpoints to calculate how many items to show in the list at each width interval
    // it will always fall back to these:
    { end: 576, size: 1 },
    { start: 576, end: 768, size: 2 },
    { start: 768, end: 992, size: 3 },
    { start: 992, end: 1200, size: 4 },
    { start: 1200, size: 5 },
  ],
  navigation: {
    // when to show navigation
    start: 992,
    color: "#000",
  },
  position: {
    // Start from '1' on mounted.
    start: 1,
  },
  autoplay: {
    // enable/disable playing slideshow
    play: true,
    // the delay duration between slides in milliseconds
    speed: 1800,
    // if setup, the slideshow will be in the loop.
    repeat: true,
  },
};

Advanced usage

<template>
  <div id="app">
    <section>
      <vue-horizontal-list :items="items" :options="options">
        <template v-slot:nav-prev>
          <div>👈</div>
        </template>

        <template v-slot:nav-next>
          <div>👉</div>
        </template>

        <template v-slot:start>
          <div>First Item</div>
        </template>

        <template v-slot:end>
          <div>Last Item</div>
        </template>

        <template v-slot:default="{ item }">
          <div class="item">
            <h5>{{ item.title }}</h5>
            <p>{{ item.content }}</p>
          </div>
        </template>
      </vue-horizontal-list>
    </section>
  </div>
</template>

<script>
import Vue from "vue";
import VueHorizontalList from "@/vue-horizontal-list.vue";

export default Vue.extend({
  name: "ServeDev",
  components: {
    VueHorizontalList,
  },
  data() {
    return {
      options: {
        responsive: [
          { end: 576, size: 1 },
          { start: 576, end: 768, size: 2 },
          { start: 768, end: 992, size: 3 },
          { size: 4 },
        ],
        list: {
          // 1200 because @media (min-width: 1200px) and therefore I want to switch to windowed mode
          windowed: 1200,

          // Because: #app {padding: 80px 24px;}
          padding: 24,
        },
        position: {
          start: 2,
        },
        autoplay: { play: true, repeat: true, speed: 2500 },
      },
      items: [
        { title: "Item 0", content: "Content item with description" },
        { title: "Item 1", content: "Content item with description" },
        { title: "Item 2", content: "Content item with description" },
      ],
    };
  },
});
</script>

<style>
body {
  margin: 0;
  padding: 0;
}

#app {
  max-width: 1400px;

  margin-left: auto;
  margin-right: auto;

  padding: 80px 24px;
}

@media (min-width: 1200px) {
  #app {
    padding-left: 80px;
    padding-right: 80px;
  }
}
</style>

Development

yarn # to setup
yarn run examples:serve # to dev and test

Contributions

For any question or feature request please feel free to create an issue or pull request.

Download Details:

Author: fuxingloh

Demo: https://fuxingloh.github.io/vue-horizontal-list/

Source Code: https://github.com/fuxingloh/vue-horizontal-list

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.