vue-smoothie

๐Ÿน Next-gen native smooth scrolling component library for Vue 3
810 26
Install
npm install vue-smoothie
Latest Version:1.2.0
Vue:3
License:MIT
Last Updated:Dec 27, 2022
Links: GitHub  ·  npm
Maintainer: zeokku

๐Ÿน Next-gen compact native smooth scrolling component library for Vue 3

โšก No scrollbar reinventing using DOM elements, no weird logic, only native scroll event, a sprinkle of CSS magic and the power of ResizeObserver.

โšก Native means the library doesn't interfere with scroll logic at all. Every scroll feature works as it should be.

DEMO (EXAMPLE SOURCE)

npm npm Discord


Installation:

pnpm add vue-smoothie
# or
yarn add vue-smoothie
# or
npm i vue-smoothie

Usage:

You should use the component as a container element for your scrollable content. The container has overflow: auto by default.

<script setup>
import { Smoothie } from "vue-smoothie";
</script>

<template>
  <Smoothie class="container">
    <div>
      <p>Test paragraph</p>
    </div>
  </Smoothie>
</template>

<style>
.container {
  /* define height and/or width */
}
</style>

There are two flavors of the component:

  • Smoothie - use this when you only need vertical scroll.
  • OmniSmoothie - use this when you need both vertical and horizontal scroll. In this case prefer using OmniSmoothie component for all scrollable areas even if they're vertical-only to prevent bundling both flavors simultaneously.
โš  Currently there's a bug on Firefox for horizontal scroll, which adds an extra scroll space based on scroll speed

weight prop

You can setup how smooth the scrolling is by specifying an optional weight prop: <Smoothie :weight="0.03"> The lower the value the lazier transition

Exposed properties

Both flavors expose an object via ref with properties:

  • el - container DOM element (available in onMounted hook)
  • x and y - current smooth scroll position (x only in Omni)

Common issues

  • To make root (App) view work with smoothie you have to pass down overflow to the smoothie element. One way of doing so is:

    html,
    body,
    #app,
    .container {
      height: 100%;
    }
    

    where #app is the element you mount your Vue application on and .container a class applied to root <smoothie> element

  • Instead of styling #app with padding and etc, better style scroll container

  • Don't forget about box-sizing: border-box when a container has border and/or padding to accommodate it into its width and height to prevent multiple scrollbars, root-level (<html>) scrollbar overtaking overflow and other issues

  • Scrollbar appears inside of page not at a side - you need to set width to 100%

Related Packages

vue3-smooth-scroll

Simple vue smooth scroll

209,775 34
vue2-smooth-scroll

Simple vue smooth scroll

127,387 121
v-smooth-scroll

Simple vue smooth scroll

65,632 19
lenis

How smooth scroll should be

35,838,808 16,917
@tempfix/lenis

How smooth scroll should be

38,878 16,786

Version History

Version Released Vue License
1.2.0 ^3.0.0 MIT
1.0.1 ^3.2.0 MIT
1.0.0 ^3.2.0 MIT