vanilla-js lightweight custom HTML scrollbar

Overview



FakeScrolllightweight custom-looking scrollbars

  • 1.4KB gzipped (js)
  • 4.0KB minified (js)
  • 7.7KB unminified (js)
  • ~20+ KB avarage similar scripts (unminified)

Currently only supports vertical scroll due to cultural norms

While there is somewhat of a support for scrollbar customization through CSS, it is not fully supported in all browsers / older versions and the level of customization isn't flexible enough to allow creativity or certain special product needs.

👉 Make sure to import fakescroll.css

React port

import FakeScroll from '@yaireo/fakescroll/react.fakescroll.js'
import '@yaireo/fakescroll/fakescroll.css'

const onFakeScrollChange = ({ scrollRatio }) => console.log(scrollRatio)

<FakeScroll className='foo' track='smooth' onChange={onFakeScrollChange}>
    ...
</FakeScroll>

Example markup:

<div class="foo">
    ...
    ...
    ...
</div>

Initialize custom scrollbar with callback:

var myScrollbar = document.querySelector('.foo').fakeScroll({
    onChange: () => console.log( myScrollbar.scrollRatio )
})

The onChange also has a scrollRatio propery in its argument:

document.querySelector('.foo--outside').fakeScroll({
    onChange: ({ scrollRatio }) => console.log( scrollRatio )
});

The above markup will now become:

<div class="foo fakeScroll fakeScroll--hasBar">
    <div class="fakeScroll__wrap">
        <div class="fakeScroll__content">
            ...
            ...
            ...
        </div>
    </div>
    <div class="fakeScroll__bar"></div>
</div>

Browser support

The script probably won't work on IE without Babel & ES2015 polyfills.

DEMO PAGE

Settings

Name Type Default Info
classname String "" Class name which is added to the scrollbar Track element
track Boolean/String false enable track events. use "smooth" for smooth "jumping"
onChange Function Callback function whenever the scroll updates
Comments
  • Give the .fakeScroll__track div a class when there is nothing to scroll

    Give the .fakeScroll__track div a class when there is nothing to scroll

    When no scrolling is necessary, the .fakeScroll__bar div is hidden with display: none. This is good, but I think it would also be good if the .fakeScroll__track div was given a class like .fakeScroll__has_hidden_bar or something along those lines so that developers could more easily update the styling of the track when there is nothing to scroll.

    enhancement 
    opened by ataylor32 7
  • Needs License

    Needs License

    It looks nice, and I can see it working in react very well (add the code in componentDidMount) and might serve my purpose to have a consistent scroll bar look and feel across all platforms, as opposed to Windows's ugly and fixed 25pixel wide monstrosity.

    However, I can't use it without a license. Nobody can. I know it is here in the public, but without a license anybody who uses it is in risk of copyright violation.

    opened by acroyear 7
  • Scrollbar moves away from pointer

    Scrollbar moves away from pointer

    It is quite annoying that when the scrollbar is hiding and you move the cursor on it, it moves to it's active position but that's not under the cursor anymore. Basically it avoids the pointer. Apart from this, it's a great script.

    opened by csakip 4
  • Improve bar usability

    Improve bar usability

    There are a couple of usability issues with the bar:

    1. With a native scrollbar, clicking in the track below the bar will cause the content to scroll down. With fakescroll, clicking in the track below the bar doesn't do anything.
    2. You can't interact with the bar on touch devices
    opened by ataylor32 2
  • Is there a way to trigger a bar styling update?

    Is there a way to trigger a bar styling update?

    I have a div that I'm using fakescroll on. If I replace the content of that div, the bar's height, which indicates how much content there is, remains the same until I hover over the div. Is there something I can do to tell fakescroll to update the bar's height?

    help wanted 
    opened by ataylor32 2
  • Can't select (highlight) text on last line

    Can't select (highlight) text on last line

    The absolute positioned .scrollWrap::after blocks mouse selection, You can reproduce in the Demo page: http://yaireo.github.io/fakescroll/ Just try to select the last line of text.

    opened by shem86 2
  • Bump minimist from 1.2.5 to 1.2.6

    Bump minimist from 1.2.5 to 1.2.6

    Bumps minimist from 1.2.5 to 1.2.6.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • I might be dumb but I can't make it work

    I might be dumb but I can't make it work

    I just wanted to say that I tried different methods and I just couldn't make it work, unfortunately. I append the files, they're being downloaded based on console logs, but I can't make it work anyway. The markup doesn't change. Kinda sad, maybe you should consider rewriting the readme? :/

    opened by wittywolk 1
  • Scrolling horizontally

    Scrolling horizontally

    Is a horizontal scrollbar also supportet? Please note, that it would be great if you have a horizontal "scrollwheel" like a apple magic mouse has, that this is also supported then. If so, it would be great to show this also in the demo and document it.

    thx!

    enhancement 
    opened by Grienauer 6
Releases(v2.5.1)
  • v2.5.1(Apr 10, 2021)

  • v2.5.0(Apr 10, 2021)

      • 97334d5
    • workaround for NPM bug - https://github.com/npm/cli/issues/2834 a5d4481
      • 06a991f
      • e878a02
      • added "onChange" to the react port - moved "onScrollResize" deceleration before it's first used 6deedb0
    • refactored to add "onChange" callback 7dc5dd3
    • further improved demo fbd7646
    • visual improvements to the demo page 8facd92
    • changed js code to iife format 8aed47d
    • removed npmignore file 84f7a9e
      • refactor to package.json c440d4d

    https://github.com/yairEO/fakescroll/compare/v2.2.1...v2.5.0

    Source code(tar.gz)
    Source code(zip)
  • v2.2.1(Jan 18, 2021)

    • [REFACTOR] - improved the way the scrollbar is hidden so it will be more accurate, regardless of it's width 11336b0
      • 061ac43

    https://github.com/yairEO/fakescroll/compare/v2.2.0...v2.2.1

    Source code(tar.gz)
    Source code(zip)
Owner
Yair Even Or
Client-side web developer, UX tinker and UI maker.
Yair Even Or
A custom ESLint rule to allow static deps in React Hooks ⚛️

eslint-plugin-react-hooks-static-deps A custom ESLint rule to allow static deps in React Hooks ⚛️ Motivation react-hooks/exhaustive-deps is a really n

Stoïk 3 Apr 5, 2022
react-dialog is a custom react hook to use a dialog easily

react-dialog react-dialog is a custom react hook to use a dialog easily. Documentation To use react-dialog follow the documentation. useDialog Returns

Levy Mateus Macedo 2 Mar 29, 2022
Shopify app using NextJS. No custom NextJS server needed.

Shopify NextJS App Example An example app built with NextJS that can be setup and deployed to production in seconds on Vercel. All the glory goes back

reda 35 Nov 29, 2022
A custom react hook to use a dialogs easily.

dialog-hook The dialog-hook is a custom react hook to use a dialog easily. First of all it is necessary to install the package in your project some co

Levy Mateus Macedo 2 Mar 29, 2022
This is a custom recipe app called chefMaster. which contains a lot of interesting such as many apis requests, filter, search , add posts. Property design

In the project directory, you can run: npm start Runs the app in the development mode. Open http://localhost:3000 to view it in the browser. The page

Andrew Smal 0 Nov 9, 2022
Set of property utilities for Stitches with theme tokens support. Use the built-in utils, or easily build custom ones.

Stitches Mix Set of property utilities for Stitches with theme tokens support. Use the built-in utils, or easily build custom ones. Usage To import al

João Pedro Schmitz 12 Aug 8, 2022
Javascript-Confirm-Dialogue - Simple Confirm Dialogue with 3 Options. Vanilla JS

Javascript Dialog Box v1.0.0 Javascript Dialog Box is a simple to use library for making dialog boxes in pure Javscript. It comes with the following f

Craig Hancock 0 Jan 12, 2022
Vanilla JS spring-interpolated values

Vanilla JS spring-interpolated values

Martin Wecke 4 Feb 28, 2022
Dynamic, theme-driven, style props for vanilla-extract.

Rainbow Sprinkles ?? Dynamic, theme-driven, style props for vanilla-extract. Rainbow sprinkles works similarly to @vanilla-extract/sprinkles. Like spr

Wayfair Tech 90 Dec 23, 2022
Dynamic, theme-driven, style props for vanilla-extract.

Rainbow Sprinkles ?? Dynamic, theme-driven, style props for vanilla-extract. Rainbow sprinkles works similarly to @vanilla-extract/sprinkles. Like spr

Wayfair Tech 37 May 11, 2022
A lightweight Apple Music client for Windows, built with MusicKit JS, Edge WebView2 and React.

Lito Music English | 中文 Lito (/laɪto/) Music is a lightweight Apple Music client for Windows, built with MusicKit JS, Edge WebView2 and React. System

Jiahao Lu 113 Dec 30, 2022
A very lightweight and flexible accessible modal dialog script.

A11y Dialog This is a lightweight (1.3Kb) yet flexible script to create accessible dialog windows. Documentation ↗ Demo on CodeSandbox ↗ Features: Clo

Kitty Giraudel 2.1k Jan 2, 2023
A lightweight package to easily track window size in React.js

useWindowSizes - a custom React hook A lightweight package to easily track window width & height in React.js Comes in handy for responsize design and

Harry Fox 3 Feb 3, 2022
A lightweight (1.7 kB) package to easily track mouse position in React.js

useMousePosition - a custom React hook A lightweight (1.7 kB) package to easily track mouse position in React.js Install npm install react-use-mouse-p

Harry Fox 17 Dec 1, 2022
How to submit HTML forms to Google Sheets. (Updated for 2021 Script Editor)

Submit a HTML form to Google Sheets How to submit a simple HTML form to a Google Sheet using only HTML and JavaScript. Updated for Google Script Edito

Levi Nunnink 314 Jan 6, 2023
HTML CSS & React - Client side dynamic e-commerce website (stripe integrated)

Furniture E-Commerce Project Description React front-end full operating dynamic and responsive E-Commerce shop including payment connection (stripe) B

Almog Wertzberger 15 Dec 27, 2022
React-app - Building volume rendering web app with VTK.js,react & HTML Using datasets provided in vtk examples (head for surface rendering and chest for ray casting)

SBE306 Assignment 4 (VTK) data : Directory containing Head and Ankle datasets Description A 3D medical viewer built with vtk-js Team Team Name : team-

Mustafa Megahed  2 Jul 19, 2022
A recipe website built for my girlfriend who loves cooking, using Sass, JavaScript, Parcel, and HTML

Forkify-App Live Link Project Introduction Forkify is a recipe web app using the Forkify API to allow users to search, view, modify, bookmark and add

JungFF 14 Sep 29, 2022
Makes the HTML element dialog draggable

Makes the HTML element dialog draggable

Naeemo 2 Sep 9, 2022