• Stars
    star
    363
  • Rank 117,374 (Top 3 %)
  • Language
    JavaScript
  • License
    GNU Affero Genera...
  • Created over 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

vanilla-js lightweight custom HTML scrollbar



FakeScrollโšกlightweight 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

Install (CDN):

npm i @yaireo/fakescroll

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

More Repositories

1

tagify

๐Ÿ”– lightweight, efficient Tags input component in Vanilla JS / React / Angular / Vue
HTML
3,466
star
2

fancyInput

Makes typing in input fields fun with CSS3 effects
CSS
1,928
star
3

photobox

A lightweight CSS3 image viewer that is pretty to look and and easy to use
JavaScript
747
star
4

knobs

UI knobs controllers for JS/CSS live manipulation of various parameters
JavaScript
305
star
5

pathAnimator

Moves a DOM element along an SVG path (or do whatever along a path...)
HTML
261
star
6

validator

HTML form validation. Perfectly made for all scenerios, lightweight, semantic & easy to use
JavaScript
258
star
7

stickyfloat

This plugin makes it possible to have a fixed position element that is relative to itโ€™s parent. A normal fixed positioned element would be โ€œout of contextโ€ and is very difficult to use in the most common situations with fluid designs. This plugin solves that problem with as little code as I could possible get it so it will run in the most optimized way, while also allow you to customize it in many important ways which might suit you best.
CSS
167
star
8

ui-range

Beautiful UI-Range input component, highly customisable, based on CSS variables. including a floating output value, min & max values on the sides & ticks according to the steps
SCSS
101
star
9

console-colors

Browser Console logs with colors
JavaScript
81
star
10

color-picker

Minimal javascript color picker component
JavaScript
61
star
11

relative-time

javascript function to transform timestamp or date to local relative-time
JavaScript
40
star
12

Do-in

Run tasks repeatedly in a fixed duration
HTML
24
star
13

dragsort

Animated drag sorting for horizontal list items
JavaScript
21
star
14

letterer

breaks a DOM node text into separate letters
HTML
16
star
15

touchy

JavaScript
16
star
16

dateRangePicker

pick a range between dates (months) or from presets
JavaScript
13
star
17

hover-carousel

mouse-position relative carousel
JavaScript
12
star
18

title-tooltip

Automatically converts HTML title attributes to nicer better tooltips
JavaScript
12
star
19

jqSwipe

Minimal swipe special event for touch-enabled devices
JavaScript
11
star
20

simpleGrid

the most performant grid system for same-size items
JavaScript
10
star
21

react-bouncer

Delay rendering of a React component with Debounce, Throttle, or any custom method
9
star
22

infinite

smart endless scrolling
JavaScript
9
star
23

listBreaker

split HTML lists into lists chunks
JavaScript
8
star
24

react-number-input

Renders native number input as a locale number (on blur) and reverts back to a workable number (on focus)
JavaScript
8
star
25

position

Position a DOM element at a certain X,Y or next to another element
JavaScript
6
star
26

react-ref-watcher

Watchable refs changes with conditional re-renders
JavaScript
6
star
27

input_indicator

JavaScript
5
star
28

ui-switch

React Switch component based on native checkbox input, using CSS variables (custom properties) as much as possible. Easily customisable and super lightweight.
JavaScript
4
star
29

react-hooks

React Hooks authored by myself
JavaScript
3
star
30

carouselite

basic, light-weight Carousel jQuery plugin
JavaScript
3
star
31

javascript-interview-questions

javascript interview questions
2
star
32

endless

infinite scrolling jQuery plugin
JavaScript
2
star
33

password-unveil

Unveil password input fields on mouse hover
JavaScript
2
star
34

Mini-page-navigation

lets the user navigate through a web page using a "mini-page" helper on the side of the page, so the user could see where he is in relation to page as a whole, (showing the actual page as a small canvas image)
2
star
35

gulp-file-contents-to-keys

convert files into key/value objects where key is filename, value is the content
JavaScript
2
star
36

translation-yaml-manager

A UI-only system which intends to ease the process of managing YAML translations files across multiple languages
1
star
37

gulp-template-compile-es6

Compile template files to ES6 exported functions
JavaScript
1
star
38

saSlider

Super Awesome Slider - jQuery plugin
CSS
1
star
39

sb-issue-performance-essentials-addon

issue report for Storybook slow rendering
JavaScript
1
star
40

self-descriptive-numbers

Generates self-descriptive numbers
HTML
1
star
41

sb-issue--react-client

Strobook issue #17926
JavaScript
1
star
42

tagify-react-test

Basic React test app for "@yaireo/tagify" package
JavaScript
1
star
43

ToDo

JavaScript
1
star
44

jQuery-ajax-delay

Wrapper for jQuery AJAX method which sets a random delay which simulates real-world latency
JavaScript
1
star
45

multi-range-slider

Custom input element for multiple sliders in one range
JavaScript
1
star
46

swc-js-extension-fails-with-jsx-content

For SWC bug report
JavaScript
1
star