项目作者: fuxingloh

项目描述 :
A pure vue native horizontal list implementation for mobile/touch and responsive web.
高级语言: Vue
项目地址: git://github.com/fuxingloh/vue-horizontal-list.git
创建时间: 2020-01-13T10:59:42Z
项目社区:https://github.com/fuxingloh/vue-horizontal-list

开源协议:MIT License

下载


👋 You might want to use Vue Horizontal instead!

Vue Horizontal
is another take on the horizontal layout written by me with an ultra simple implementation that is extensible and moves the
responsibility to the user rather than the library.
With zero dependencies, 3 KB for CDN users it’s built for your production needs.

Vue Horizontal is a rewrite of this library with many more focus such as
end-to-end testing on real browsers, SSG/SSR CI testing to make sure all code is SSG/SSR compliant for your SEO!
Documentation are also extensible with everything you can think of about horizontal layout documentation through and through.

Vue Horizontal also contains a snippet dossier with many SPA/SSR/SSG
friendly recipes for your design needs.
Vue Horizontal is not just a library, it’s a place for everything horizontal.

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.

code style: prettier
License MIT
Latest Release
Contributors
Issues
GitHub Pages
CI


vue-horizontal-list screenshot

Installation

```shell script
npm i vue-horizontal-list

or

yarn add vue-horizontal-list

  1. Check out this [alternative project](https://github.com/fuxingloh/vue-horizontal) maintained by me for a new take on horizontal layout in vue.
  2. #### Basic usage
  3. ```vue
  4. <vue-horizontal-list
  5. :items="items"
  6. :options="{
  7. responsive: [
  8. { end: 576, size: 1 },
  9. { start: 576, end: 768, size: 2 },
  10. { size: 3 },
  11. ],
  12. }"
  13. >
  14. <template v-slot:default="{item}">
  15. <div class="item">
  16. <h5>{{item.title}}</h5>
  17. <p>{{item.content}}</p>
  18. </div>
  19. </template>
  20. </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

  1. const options = {
  2. item: {
  3. // css class to inject into each individual item
  4. class: "",
  5. // padding between each item
  6. padding: 12,
  7. },
  8. list: {
  9. // css class for the parent of item
  10. class: "",
  11. // maximum width of the list it can extend to before switching to windowed mode, basically think of the bootstrap container max-width
  12. // windowed is used to toggle between full-screen mode and container mode
  13. windowed: 1200,
  14. // padding of the list, if container < windowed what is the left-right padding of the list
  15. // during full-screen mode the padding will added to left & right to centralise the item
  16. padding: 24,
  17. },
  18. responsive: [
  19. // responsive breakpoints to calculate how many items to show in the list at each width interval
  20. // it will always fall back to these:
  21. { end: 576, size: 1 },
  22. { start: 576, end: 768, size: 2 },
  23. { start: 768, end: 992, size: 3 },
  24. { start: 992, end: 1200, size: 4 },
  25. { start: 1200, size: 5 },
  26. ],
  27. navigation: {
  28. // when to show navigation
  29. start: 992,
  30. color: "#000",
  31. },
  32. position: {
  33. // Start from '1' on mounted.
  34. start: 1,
  35. },
  36. autoplay: {
  37. // enable/disable playing slideshow
  38. play: true,
  39. // the delay duration between slides in milliseconds
  40. speed: 1800,
  41. // if setup, the slideshow will be in the loop.
  42. repeat: true,
  43. },
  44. };

Advanced usage

  1. <template>
  2. <div id="app">
  3. <section>
  4. <vue-horizontal-list :items="items" :options="options">
  5. <template v-slot:nav-prev>
  6. <div>👈</div>
  7. </template>
  8. <template v-slot:nav-next>
  9. <div>👉</div>
  10. </template>
  11. <template v-slot:start>
  12. <div>First Item</div>
  13. </template>
  14. <template v-slot:end>
  15. <div>Last Item</div>
  16. </template>
  17. <template v-slot:default="{ item }">
  18. <div class="item">
  19. <h5>{{ item.title }}</h5>
  20. <p>{{ item.content }}</p>
  21. </div>
  22. </template>
  23. </vue-horizontal-list>
  24. </section>
  25. </div>
  26. </template>
  27. <script>
  28. import Vue from "vue";
  29. import VueHorizontalList from "@/vue-horizontal-list.vue";
  30. export default Vue.extend({
  31. name: "ServeDev",
  32. components: {
  33. VueHorizontalList,
  34. },
  35. data() {
  36. return {
  37. options: {
  38. responsive: [
  39. { end: 576, size: 1 },
  40. { start: 576, end: 768, size: 2 },
  41. { start: 768, end: 992, size: 3 },
  42. { size: 4 },
  43. ],
  44. list: {
  45. // 1200 because @media (min-width: 1200px) and therefore I want to switch to windowed mode
  46. windowed: 1200,
  47. // Because: #app {padding: 80px 24px;}
  48. padding: 24,
  49. },
  50. position: {
  51. start: 2,
  52. },
  53. autoplay: { play: true, repeat: true, speed: 2500 },
  54. },
  55. items: [
  56. { title: "Item 0", content: "Content item with description" },
  57. { title: "Item 1", content: "Content item with description" },
  58. { title: "Item 2", content: "Content item with description" },
  59. ],
  60. };
  61. },
  62. });
  63. </script>
  64. <style>
  65. body {
  66. margin: 0;
  67. padding: 0;
  68. }
  69. #app {
  70. max-width: 1400px;
  71. margin-left: auto;
  72. margin-right: auto;
  73. padding: 80px 24px;
  74. }
  75. @media (min-width: 1200px) {
  76. #app {
  77. padding-left: 80px;
  78. padding-right: 80px;
  79. }
  80. }
  81. </style>

Development

shell script 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.